Skip to content

[Suggestion]: Should server functions be wrapped in transitions? (conflicting info in the docs) #7734

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

Open
gmoniava opened this issue Apr 11, 2025 · 0 comments

Comments

@gmoniava
Copy link

gmoniava commented Apr 11, 2025

Summary

Here it says:

When using a Server Function outside a form, call the Server Function in a Transition, which allows you to display a loading indicator, show optimistic state updates, and handle unexpected errors

Which seems to suggest we should always wrap server functions in transitions when using them outside forms.

However here is example from docs without wrapping them in transitions:

// Server Component
import Button from './Button';

function EmptyNote () {
  async function createNoteAction() {
    // Server Function
    'use server';
    
    await db.notes.create();
  }

  return <Button onClick={createNoteAction}/>;
}
// Client 
"use client";

export default function Button({onClick}) { 
  console.log(onClick); 
  // {$$typeof: Symbol.for("react.server.reference"), $$id: 'createNoteAction'}
  return <button onClick={() => onClick()}>Create Empty Note</button>
}

Can docs make it clearer which to use?

Page

https://react.dev/reference/rsc/use-server#calling-a-server-function-outside-of-form
https://react.dev/reference/rsc/server-functions#creating-a-server-function-from-a-server-component

Suggestion

It should be made more clear whether both approaches are allowed or not and if allowed, what are pros cons of each.


PS. Initially I had opened this issue as typo/mistake but I guess Suggestion is a better fit, changed title, but old label remains.

@gmoniava gmoniava changed the title [Typo]: Should server functions be wrapped in transitions or not? (conflicting info in the docs) [Typo]: Should server functions be wrapped in transitions? (conflicting info in the docs) Apr 11, 2025
@gmoniava gmoniava changed the title [Typo]: Should server functions be wrapped in transitions? (conflicting info in the docs) [Suggestion]: Should server functions be wrapped in transitions? (conflicting info in the docs) Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant