Skip to content

feat: reload stale clients after new deployments in single fetch - #15518

Closed
uncoolclub wants to merge 4 commits into
remix-run:mainfrom
uncoolclub:version-skew-single-fetch
Closed

uncoolclub wants to merge 4 commits into
remix-run:mainfrom
uncoolclub:version-skew-single-fetch

Conversation

@uncoolclub

@uncoolclub uncoolclub commented Sep 16, 2026 •

Copy link
Copy Markdown

Adds future.unstable_detectVersionSkew so a tab that's been open across a deploy notices it's talking to a newer server.

Discussion: #15517. Draft because I'm not sure the flag belongs where I put it; the "Things I'm unsure about" section says why.

The gap

Route discovery compares build versions, but only when it fetches the manifest, and it skips that fetch for paths the tab already knows:

// packages/react-router/lib/dom/ssr/fog-of-war.ts
if (discoveredPaths.has(path)) return;

So: tab opens, we deploy, user clicks a link to a route they've already visited. The tab fetches .data from the new server and hands it to old components. Nothing compared anything.

That bit us when a loader field got renamed. The API kept both names for a release, but our zod schema on the new server dropped the old one, and tabs that had been sitting open threw on oldField.name.

RSC doesn't have this problem — getFetchAndDecodeViaRSC has compared the build version on every data fetch since #15318.

What I did

generateSingleFetchResponse stamps X-React-Router-Build when the flag is on. The client compares it on arrival and hands off to handleClientVersionMismatch. That function already reloads the document and carries the sessionStorage guard against reload loops.

I put the comparison after the redirect branches, matching what RSC does. Get that wrong and an action redirect reloads the URL you're leaving instead of the one you're going to. I had it backwards in the first pass.

With the flag off the server sends no header and the client has nothing to compare. The new parameter on fetchAndDecodeViaTurboStream is optional, so existing callers are unaffected. It's also forced off in dev, where the manifest version changes every time you edit a route's exports; leaving it on there turns every HMR edit into a full reload.

It's opt-in because reloading the document throws away whatever's half-typed in a form. And if you keep old builds addressable, you never hit the skew at all.

Things I'm unsure about

The flag lives in future, and that's the part I'd most like you to weigh in on. Putting it there meant making the framework's FutureConfig extend the router's. That relationship was already implicit — the framework passes its future object straight into createStaticRouter — but nobody had written it down, and I'd rather you decide whether writing it down is right. unstable_subResourceIntegrity ended up as a top-level option instead, so there's precedent for the other shape.

The header name is the other thing. Everything else in single fetch is X-Remix-*. I didn't want to add to a prefix you're presumably moving away from, but X-React-Router-Build starts a second family, and I don't know which of those you'd rather live with.

I also put the version in a header rather than the payload, where RSC puts it. Prerendered .data files are written from the response body, so a version baked into that body freezes at build time and mismatches forever after the next deploy. A header isn't written into the prerendered file at all, so the client finds nothing to compare and detection stays off, which is the right failure for a static file.

Testing

integration/version-skew-test.ts covers four cases: a .data response from a different build reloads the document, matching versions don't, an action redirect lands on its target, and no header goes out with the flag off.

I checked the first and third by deleting the version comparison, then the redirect ordering; each test fails on its own deletion. The other two pin the flag-off path, where there's no code to delete.

single-fetch-test.ts and fog-of-war-test.ts still pass — 97 tests across the two. Change files are in both packages/react-router/.changes/ and packages/react-router-dev/.changes/.

Add `future.unstable_detectVersionSkew` so a stale client notices it is
consuming data from a newer server build.

Route discovery already compares build versions, but only on manifest
requests, and `patchRoutesOnNavigation` returns early for paths the tab has
already discovered. A navigation between discovered routes therefore fetches
`.data` from the new server with no comparison, and the old client renders
data whose shape may have changed.

When the flag is on, the server stamps its build version onto every
single-fetch response and the client compares it on arrival, reusing
`handleClientVersionMismatch` and its sessionStorage loop guard. This is what
the RSC path has done on every data fetch since remix-run#15318.

Opt-in because the resulting document navigation discards in-flight form
state, and deployments that keep previous builds addressable do not need it.
- fix: compare versions after the redirect branches so an action redirect
  follows through to its target instead of reloading the URL it is leaving
- fix: leave the flag off in dev, where the manifest version changes on every
  route-export edit and would turn HMR into a document reload
- refactor: read the flag from `build.future` via an intersection type rather
  than duplicating it as a top-level `ServerBuild` field
- test: assert the server actually stamps the client's own version, and cover
  the action redirect path
- docs: add the flag to the future flags page, and note the cached `.data`,
  prerender, and RSC caveats
- refactor: keep `fetchAndDecodeViaTurboStream` a standalone function and take
  the client version through a third parameter

Wrapping the body in a factory re-indented ~140 lines, which buried the real
change and would have rewritten `git blame` for the whole function. The diff is
now 34 added lines and 1 changed.
@uncoolclub uncoolclub changed the title Detect version skew on single fetch data requests Add opt-in version skew detection for single fetch requests Sep 16, 2026
@uncoolclub uncoolclub changed the title Add opt-in version skew detection for single fetch requests feat: reload stale clients after new deployments in single fetch Sep 16, 2026
@uncoolclub
uncoolclub marked this pull request as ready for review September 16, 2026 01:59
@uncoolclub
uncoolclub marked this pull request as draft September 17, 2026 01:05
@brophdawg11

Copy link
Copy Markdown
Contributor

Can you post a github comparison link to your fork in the discussion? We don't usually move to opening a PR until weve discussed and accepted the proposal over there first. Thanks!

@uncoolclub

uncoolclub commented Sep 19, 2026 •

Copy link
Copy Markdown
Author

Got it, thanks! posted the comparison link in #15517.

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.

2 participants