Clarify that an action's result is flat (res.field), not res.data.field#44
Open
shivamsn97 wants to merge 1 commit into
Open
Clarify that an action's result is flat (res.field), not res.data.field#44shivamsn97 wants to merge 1 commit into
res.field), not res.data.field#44shivamsn97 wants to merge 1 commit into
Conversation
An @action's awaited result is the flat { ok, ...yourReturn } — returned fields sit directly on it (res.title), and a successful result has no .data. Because useAction separately exposes a .data property (the last successful return), it was easy to write res.data.title, which is undefined on success and silently no-ops inside `if (res.ok)`, so a mutation appeared to do nothing until the page reloaded. Spell out the contract and warn against res.data.x in the scaffolded AGENTS.md, the Server Actions guide, and the client API reference; drop an ambiguous ...data spread in the README example; add a changelog note. No behavior change — the shipped TypeScript types already modelled this correctly.
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.
An
@action's awaited result on the client is the flat{ ok, ...yourReturn }— your returned fields sit directly on it (res.title), and a successful result has no.data. ButuseActionalso exposes a separate.dataproperty (the last successful return), and it's easy — for a person or an AI coding agent — to conflate the two and writeres.data.title. On success that'sundefined, so it silently no-ops insideif (res.ok)and the mutation looks like it did nothing until the page reloads.The runtime and the shipped TypeScript types were already correct — the prose was the weak link. This makes the contract explicit everywhere it's taught:
AGENTS.md— the result-shape rule, theuseActionexample, the toolkit reference, and a new DON'T all state that fields are top-level (res.x) and warn againstres.data.x..dataproperty....dataspread.No behavior change. A fresh
pyxle initemits the updated guidance and the CLI/scaffold suite stays green.