Fix Server Function signature and two typos in 'use server' reference - #8653
Open
BlackHatMan wants to merge 1 commit into
Open
Fix Server Function signature and two typos in 'use server' reference#8653BlackHatMan wants to merge 1 commit into
BlackHatMan wants to merge 1 commit into
Conversation
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.
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
SapanMozammel
left a comment
There was a problem hiding this comment.
Nice catch! Adding prevState properly aligns with the React 19 useActionState signature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three small fixes to
src/content/reference/rsc/use-server.md, all still present onmain.Closes #7644.
1.
requestUsernamehas the wrong signature foruseActionState. It is defined asrequestUsername(formData)but passed touseActionState(requestUsername, null, 'n/a'). React calls the action with the previous state first, soformDatareceivesnullandformData.get('username')throws.The
useActionStatereference already documents this exact mistake under "My Action cannot read form data" and prescribesfunction action(prevState, formData). This applies that, using theprevStatenaming 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>, whereFormDatagenuinely 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 toreference/rsc/. Credit to @alexandreferreirafr for finding it first.2. Stray
;inside JSX in theLikeButtonexample. 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.mdbanner 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.