Skip to content

Conversation

rickhanlonii
Copy link
Member

Copy link

vercel bot commented Oct 1, 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 Oct 1, 2024 8:08pm
react-dev ✅ Ready (Inspect) Visit Preview Oct 1, 2024 8:08pm

* Server Functions should be called in a [Transition](/reference/react/useTransition). Server Functions passed to [`<form action>`](/reference/react-dom/components/form#props) or [`formAction`](/reference/react-dom/components/input#props) will automatically be called in a transition.
* Server Functions are designed for mutations that update server-side state; they are not recommended for data fetching. Accordingly, frameworks implementing Server Functions typically process one action at a time and do not have a way to cache the return value.
* Server Functions are typically used in Actions to update server-side state; if you need to fetch data from the server, consider using a [Server Component](/reference/rsc/server-components).
* By convention, Server Functions used in Actions such as inside a [Transition](/reference/react/useTransition), passed to [`<form action>`](/reference/react-dom/components/form#props), or passed to [`formAction`](/reference/react-dom/components/input#props) are called Server Actions.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm some Transitions are navigations right? And not Actions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I want this to say "in Actions" and link directly to that section of Transitions, but that doesn't exist yet. I didn't intend for this to imply all Transitions are Actions, any idea how to clarify?

Copy link
Member

Choose a reason for hiding this comment

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

How about like:

By convention, Server Functions that perform a mutation of some kind (i.e., that do not merely fetch data) and are called in a context that integrates with React's handling of async operations (such as inside …) are called Server Actions.

That's wordy and maybe can be refactored but I think this is correct? For Actions in general I think it means:

  • State updates are transition priority [server actions couldn't possibly trigger sync updates, of course]
  • Ties into isPending, optimistic, and error handling
  • Might have side effects (other than calling setState) so must be called in a context where React will call them exactly once / can't be interrupted or rebased

Note that the first two are true of navigation-style transitions too.

@rickhanlonii rickhanlonii deleted the branch reactjs:v19 December 5, 2024 19:03
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.

3 participants