Skip to content

Clarify that an action's result is flat (res.field), not res.data.field#44

Open
shivamsn97 wants to merge 1 commit into
mainfrom
docs/action-result-shape
Open

Clarify that an action's result is flat (res.field), not res.data.field#44
shivamsn97 wants to merge 1 commit into
mainfrom
docs/action-result-shape

Conversation

@shivamsn97

Copy link
Copy Markdown
Member

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. But useAction also exposes a separate .data property (the last successful return), and it's easy — for a person or an AI coding agent — to conflate the two and write res.data.title. On success that's undefined, so it silently no-ops inside if (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:

  • Scaffold AGENTS.md — the result-shape rule, the useAction example, the toolkit reference, and a new DON'T all state that fields are top-level (res.x) and warn against res.data.x.
  • Server Actions guide — a note disambiguating the awaited result from the hook's .data property.
  • Client API reference — the same note beside the return-value table.
  • README — the inline comment drops an ambiguous ...data spread.
  • Changelog — entry under Unreleased.

No behavior change. A fresh pyxle init emits the updated guidance and the CLI/scaffold suite stays green.

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.
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.

1 participant