GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(rsc): allow rejecting server references during decodeReply/decodeAction by james-elicx · Pull Request #1520 · vitejs/vite-plugin-react

Conversation

@james-elicx

@james-elicx james-elicx commented Oct 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Description

decodeReply, decodeAction, and decodeFormState always decode with the plugin's server manifest, which resolves any server reference the client sends. A framework can't limit which server functions a request is allowed to decode, for example to the actions its current route exposes. Next.js does this with a page-scoped server module map, so a server function passed as an argument, or bound to a form action, has to belong to the current page.

Today a framework has to skip these wrappers and call @vitejs/plugin-rsc/vendor/react-server-dom/server.edge directly with its own manifest built on top of createServerManifest().

This adds an experimental onServerReference callback in an optional last parameter, alongside the existing onClientReference extension on renderToReadableStream:

decodeReply(body, { temporaryReferences }, { onServerReference })
decodeAction(formData, { onServerReference })
decodeFormState(result, formData, { onServerReference })

The callback receives { id, name } for each server reference React resolves while decoding. That includes the action itself in decodeAction, and any server function passed as an argument or bound to an action. Throwing rejects the reference before its module loads, and decoding fails. decodeReplyFromBusboy in @vitejs/plugin-rsc/rsc/server.node gets the same parameter. Without the callback, nothing changes.

loadServerAction doesn't call it, so for fetch actions a framework still checks the action id itself. The README says so.

Tests

New e2e/server-reference-callback.test.ts, an inline starter-extra fixture, in dev and build. Its RSC entry rejects one named server reference. Two forms bind a recording action to an allowed and a rejected server function, and each is submitted twice:

  • with JS (decodeReply);
  • without JS (decodeAction).

The rejected submissions fail with a 500 and never run the action. The allowed ones run with the bound server function. Without the source change, the rejected submissions return 200 and run the action.

decodeFormState passes the callback through too, but the test doesn't exercise it. React only decodes there for useActionState forms ($ACTION_KEY), and decodeAction already rejects the same bound references first.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
james-elicx added 2 commits October 19, 2026 11:47
@james-elicx
feat(rsc): add onServerReference callback to decode APIs
9ae6435
@james-elicx
docs(rsc): clarify onServerReference coverage
7c6cb4b
@james-elicx james-elicx changed the title feat(rsc): add onServerReference callback to decode APIs feat(rsc): allow rejecting server references during decodeReply/decodeAction Oct 19, 2026
@james-elicx
james-elicx marked this pull request as ready for review October 19, 2026 10:56
hi-ogawa and others added 14 commits October 20, 2026 11:39
@hi-ogawa @claude
chore(rsc): validate progressive actions with onServerReference in ac…
d2b3f8d
…tion-reachability example

The progressive form path rejects server references that the current route cannot reach through the `onServerReference` callback of `decodeAction` and `decodeFormState`, so React's own decoder does the checking instead of a pre-decode copy of its `$ACTION_*` field parsing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
chore(rsc): validate nested server references in action-reachability …
261780b
…example

`decodeReply` also receives the `onServerReference` validator, so a server function passed as an action argument has to be reachable from the route that runs the action, just like the progressive path. New e2e cases cover a retained action passed as an argument from another route, and a progressive form whose shared action is reachable from the replay target while the server function bound to it is not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
docs(rsc): add figures to action-reachability example README
9e53ea9
The README walks through manifest generation, request redispatch, and the decode-time check for nested server references and progressive forms, each with a figure. It also links the comparable Next.js behavior for progressive form validation and for nested server references after navigation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
refactor(rsc): declare onServerReference extension on decodeReply wra…
1e9719f
…ppers

`src/types` mirrors upstream React types, so the Vite-specific `extraOptions` parameter is declared on the `decodeReply` and `decodeReplyFromBusboy` wrappers, like `renderToReadableStream`'s, instead of on `DecodeReplyFunction` and `DecodeReplyFromBusboyFunction`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa
Merge remote-tracking branch 'origin/main' into feat/rsc-on-server-re…
c5dda5e
…ference
@hi-ogawa @claude
test(rsc): document testProgressiveAction in action-reachability e2e
fe42512
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
test(rsc): clarify how testProgressiveAction simulates a replayed form
abd2b76
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
test(rsc): name the progressive form variants in testProgressiveAction
06e8a80
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
chore(rsc): explain where action-reachability checks each server refe…
f8eca69
…rence

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
chore(rsc): explain why decodeFormState also receives onServerReference
e9a146c
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
test(rsc): reject unreachable references found by decodeFormState in …
949cdf1
…action-reachability example

`decodeFormState` decodes the last `$ACTION_REF_*` field, while `decodeAction` may use a later `$ACTION_ID_*` field, so a crafted progressive body can reach a server reference that `decodeAction` never checked. The example responds with 404 when that check fails, and a new e2e case posts such a body built from the server-rendered `/b` and `/c` forms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
test(rsc): drop crafted decodeFormState e2e case in action-reachabili…
6625ad1
…ty example

`onServerReference` runs for every server reference React resolves through the manifest, so `decodeFormState` is held to the same route by construction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
test(rsc): note which reference each progressive form replay fails on
5ef31c9
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
test(rsc): assert rejection text for retained action argument
be9cc7f
Co-Authored-By: Claude Opus 5.5 <[email protected]>
hi-ogawa
hi-ogawa approved these changes Oct 20, 2026
View reviewed changes

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks! This API makes sense. I updated examples/action-reachability to use this API instead of probing FormData and this also now covers the case of hydrated action arguments being unreachable actions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hi-ogawa
hi-ogawa merged commit 505da21 into vitejs:main Oct 20, 2026
21 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@vite-release-bot vite-release-bot Bot mentioned this pull request Nov 5, 2026
release: [email protected] #1552
Merged
This was referenced Nov 5, 2026
chore(deps): bump @vitejs/plugin-rsc to 0.5.39 cloudflare/vinext#4568
Open
refactor(actions): reject foreign server references through plugin-rsc's onServerReference cloudflare/vinext#4569
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hi-ogawa hi-ogawa hi-ogawa approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@james-elicx @hi-ogawa
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.