Skip to content

fix(rsc): detect client version skew in createCallServer action responses - #15342

Open
agcty wants to merge 2 commits into
remix-run:mainfrom
agcty:fix/rsc-call-server-client-version
Open

agcty wants to merge 2 commits into
remix-run:mainfrom
agcty:fix/rsc-call-server-client-version

Conversation

@agcty

@agcty agcty commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The clientVersion stale-client detection shipped in #15318 covers lazy route discovery (?version= → 204 + X-Remix-Reload-Document) and the router data strategy (loaders and router-driven actions compare payload.clientVersion). Server functions invoked through unstable_createCallServer — client-component form actions / useActionState / imperative calls via setServerCallback — are the one payload-applying path with no check: the action's rerender is applied unconditionally, so a stale client patches new-build route manifests and loaderData into old-build modules via patchRoutes + _internalSetState…. That's precisely the mismatched-module state the feature exists to prevent, on what is many apps' highest-write-traffic boundary.

The rerender does carry the version: baseRenderPayload includes clientVersion and feeds the action payload's rerender (the top-level action payload deliberately has no version field — the check must read rerender.clientVersion).

Change

  • Store the hydration baseline alongside the other router globals (__reactRouterClientVersion). createCallServer is constructed via setServerCallback before createRouterFromPayload runs, so it cannot close over the payload; timing is safe because no action can fire before hydration populates the global. When the feature is unwired, both sides are undefined and behavior is unchanged.
  • In the rerender path, call handleClientVersionMismatch before the action-supersede guard: skew is a whole-client condition, so a superseded action must still reload a stale document. On mismatch the stale rerender is never applied and the caller's already-resolved actionResult is unaffected (the mutation landed server-side). The existing sessionStorage loop guard applies unchanged.
  • Redirect rerenders carry no version and are deliberately untouched — they either hard-reload or navigate through the data strategy, which already checks. skipRevalidation actions carry no rerender payload to check.

Tests

Added to integration/rsc-client-version-test.ts in the file's existing pattern (route-intercept the action POST, swap the version in the rerender stream): a stale server-function rerender now reloads the destination document instead of applying. Verified red on main (test fails without the fix) and green with it; the file's four existing tests still pass.

One observation from working in this code, left out of scope: landedActionId in createCallServer is declared and read in the supersede guard but never assigned anywhere — half of that guard is dead. Happy to file separately if useful.

🤖 Generated with Claude Code on behalf of agcty

…nses

The clientVersion check added with the stale-client reload feature covers
lazy route discovery and the router data strategy, but server functions
invoked through createCallServer apply their rerender payload without a
version check — a stale client patches new-build route manifests and
loaderData into old-build modules.

Store the hydration baseline alongside the other router globals (the
callServer callback is constructed via setServerCallback before
createRouterFromPayload runs, so it cannot close over the payload) and
run handleClientVersionMismatch before the action-supersede guard: skew
is a whole-client condition, so a superseded action must still reload a
stale document. Redirect rerenders carry no version and stay unchanged —
they either hard-reload or re-enter the data strategy, which already
checks. skipRevalidation actions carry no rerender payload to check.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@granjacours697-netizen granjacours697-netizen 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.

import { index, route } from "@react-router/dev/routes";

export default [
index("./home.tsx"),
route("products/:pid", "./product.tsx"),
];

@brophdawg11 brophdawg11 self-assigned this Nov 17, 2026
@brophdawg11

Copy link
Copy Markdown
Contributor

I found one issue with the reload path. If a server function returns a rerender from a different build while the current URL is /settings#profile, assigning that URL to window.location.href can trigger a same-document fragment navigation. The client discards the rerender and records a reload attempt while the old document stays active.

I pushed a fix in 5bd4488c7 that explicitly reloads the document and preserves the query string and fragment. I also merged current main and resolved the conflict in the integration test. The regression submits an RSC server function, changes the rerender version, and verifies a new document GET with the fragment still in the address bar.

Authored by an AI agent on behalf of @brophdawg11

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants