Repository navigation
feat: reload stale clients after new deployments in single fetch - #15518
Closed
uncoolclub wants to merge 4 commits into
Closed
uncoolclub wants to merge 4 commits into
uncoolclub wants to merge 4 commits into
Conversation
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
marked this pull request as ready for review
September 16, 2026 01:59
uncoolclub
marked this pull request as draft
September 17, 2026 01:05
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! |
Author
|
Got it, thanks! posted the comparison link in #15517. |
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.
Adds
future.unstable_detectVersionSkewso 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:
So: tab opens, we deploy, user clicks a link to a route they've already visited. The tab fetches
.datafrom 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 —
getFetchAndDecodeViaRSChas compared the build version on every data fetch since #15318.What I did
generateSingleFetchResponsestampsX-React-Router-Buildwhen the flag is on. The client compares it on arrival and hands off tohandleClientVersionMismatch. That function already reloads the document and carries thesessionStorageguard 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
fetchAndDecodeViaTurboStreamis 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'sFutureConfigextend the router's. That relationship was already implicit — the framework passes its future object straight intocreateStaticRouter— but nobody had written it down, and I'd rather you decide whether writing it down is right.unstable_subResourceIntegrityended 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, butX-React-Router-Buildstarts 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
.datafiles 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.tscovers four cases: a.dataresponse 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.tsandfog-of-war-test.tsstill pass — 97 tests across the two. Change files are in bothpackages/react-router/.changes/andpackages/react-router-dev/.changes/.