Skip to content

[19] s/"Server Action"/"Server Function" #7180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 29, 2024

Conversation

rickhanlonii
Copy link
Member

@rickhanlonii rickhanlonii commented Sep 22, 2024

Overview

This PRs re-names "Server Actions" to "Server Functions" in the docs starting in React 19.

If you review the changes here, you can actually see the reason this makes sense: Many of the calls to "use server" functions are not actions.

For example, this example from the Server "Action" docs is not an Action:

"use client";
import {createNote} from './actions';

function EmptyNote() {
  console.log(createNote);
  // {$$typeof: Symbol.for("react.server.reference"), $$id: 'createNoteAction'}
  <button onClick={() => createNote()} />
}

This is just calling a server function on click. Really, it should be converted to an Action for better UX.

What are Server Actions then

Server Actions are Server Functions used in an Action context. For example, there are three examples on the Server Function page in this PR that show:

  • Using Server Functions with Actions
  • Form Actions with Server Functions
  • Server Functions with useActionState

Redirect

This change redirects links to "/server-action" to the 18 docs, which I'll add a callout for saying it's been renamed. We should also probably update the 19 blog post with a note about the name change.

Copy link

vercel bot commented Sep 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
19-react-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 29, 2024 5:15pm
react-dev ✅ Ready (Inspect) Visit Preview Sep 29, 2024 5:15pm

Copy link
Member

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…are server components server functions

@rickhanlonii rickhanlonii merged commit e03b92c into reactjs:v19 Sep 29, 2024
5 of 6 checks passed
@rickhanlonii rickhanlonii deleted the rh/19-server-functions branch September 29, 2024 19:04
@slorber
Copy link
Contributor

slorber commented Sep 30, 2024

Just passing by to report some details that confused me a bit


On the v19 docs site there are still examples using createNoteAction while the function is not an action. Maybe it would be better to rename these as well?

CleanShot 2024-09-30 at 11 02 09


Also wondering if there's a canonical place in docs that explains what are actions and server actions (as far as I understand an action is not always necessarily a server action? 🤔 )

It's explained in the v19 RC blog post:

CleanShot 2024-09-30 at 11 04 27

But I'm not sure it's explained in the docs yet, or I couldn't find it.

Maybe having a docs page about the concept of action could be useful?


Overall I'm still a bit confused by what a Server Action is.

The way I see it, an async transition might call multiple server functions.

startTransition(async function myTransition() {
  await serverFn1();
  await serverFn2();
});

Here do we consider that serverFn1 and serverFn2 are server actions? But then what about serverFn1 being called outside transitions in other places? The same function gets 2 different names depending on call sites?

Or do we consider myTransition to be a server action? (but then it's somehow a "double server action"). Or it's only a server action if we add use server to it and we directly pass the endpoint to the transition?

I'm wondering if the concept of Server Action makes sense. Maybe there are just Server Functions, Actions, and then it's possible to call Server Functions from Actions and that's it?

Comment on lines +126 to +127
const submitAction = async () => {
startTransition(async () => {
Copy link
Contributor

@slorber slorber Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wondered here why submitAction is async considering startTransition returns nothing

Is wrapping in transition necessary in this case when using <form action>? Isn't the function already an action?

rickhanlonii added a commit that referenced this pull request Dec 5, 2024
* Convert "Canary" callouts to "React 19 beta" (#6811)

* Convert "Canary" callouts to "React 19 beta"

* Starting in

* Bump version string

* Bump deploy

* Bump deploy

* Bump deploy

* [19] Remove <NextMajor> callouts (#6844)

* Remove <NextMajor> callouts

* rm if(node)

* Delete removed APIs from 19 docs (#6845)

* Add information about ref handling in strict mode (#6777)

* Add information about DOM ref handling in strict mode

* switch order of ref object / ref callback in strictmode doc

* use 'refs to components' terminology instead of 'DOM refs'

* update references to canary/r19

* Expand usage example and remove badges

---------

Co-authored-by: Rick Hanlon <[email protected]>

* [19] s/"Server Action"/"Server Function" (#7180)

* [19] s/Server Action/Server Function

* Revert /blog and change redirect

* Add note

* Tweak note

* [v19] Update sandboxes to 19 RC (#7196)

* Update transition docs for React 19 (#6837)

* Add async transitions to React 19 docs

* Updates from feedback

* tweaks

* grammar

* Add startTranstion API

* Apply suggestions from code review

Co-authored-by: Noah Lemen <[email protected]>

* Updated

* capitalization

* grammar

---------

Co-authored-by: Noah Lemen <[email protected]>

* [19] Add docs for prerender APIs (#7320)

* Add prerender APIs

* fix code blocks

---------

Co-authored-by: Noah Lemen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants