Skip to content

Fix Server Function signature and two typos in 'use server' reference - #8653

Open
BlackHatMan wants to merge 1 commit into
reactjs:mainfrom
BlackHatMan:fix-use-server-examples
Open

Fix Server Function signature and two typos in 'use server' reference#8653
BlackHatMan wants to merge 1 commit into
reactjs:mainfrom
BlackHatMan:fix-use-server-examples

Conversation

@BlackHatMan

Copy link
Copy Markdown

Three small fixes to src/content/reference/rsc/use-server.md, all still present on main.

Closes #7644.

1. requestUsername has the wrong signature for useActionState. It is defined as requestUsername(formData) but passed to useActionState(requestUsername, null, 'n/a'). React calls the action with the previous state first, so formData receives null and formData.get('username') throws.

The useActionState reference already documents this exact mistake under "My Action cannot read form data" and prescribes function action(prevState, formData). This applies that, using the prevState naming its examples use.

Note that the earlier requestUsername(formData) in the "Server Functions in forms" section is intentionally left unchanged — that one is passed directly to <form action>, where FormData genuinely is the first argument.

Same fix as #6685 (2024), which can no longer merge: it targets src/content/reference/react/use-server.md, and the page has since moved to reference/rsc/. Credit to @alexandreferreirafr for finding it first.

2. Stray ; inside JSX in the LikeButton example. It sits in the fragment's children rather than after a statement, so it is JSX text and renders a literal ; after the button. The <p> on the line above has no ; — this is a typo, not a departure from the "Use semicolons" style rule in CONTRIBUTING.

3. "for use with using React Server Components" in the RSC banner. The sibling use-client.md banner reads "for use with [React Server Components]"; this matches it. Reported in #7644 and fixed in #7645, which no longer applies cleanly because the link target changed after it was opened. Credit to @nayounsang.

No line counts change, so no code-block line highlighting is affected.

requestUsername is passed to useActionState but declared as
requestUsername(formData). useActionState calls the action with the
previous state as the first argument, so formData ends up null and
formData.get('username') throws. The useActionState reference already
covers this under "My Action cannot read form data".

Also drop a stray semicolon in the LikeButton example, where it sits in
the fragment's children and renders as text, and remove a duplicated
word in the RSC banner so it matches use-client.md.
@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@SapanMozammel SapanMozammel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice catch! Adding prevState properly aligns with the React 19 useActionState signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion]: Highlighting of RSC block in use server is different from other place.

2 participants