Fix stale data after navigation despite revalidation#95439
Open
gaearon wants to merge 2 commits into
Open
Conversation
Contributor
Tests PassedCommit: c8fa288 |
Contributor
Stats from current PR🔴 1 regression, 2 improvements
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📝 Changed Files (8 files)Files with changes:
View diffsapp-page-exp..ntime.dev.jsDiff too large to display app-page-exp..time.prod.jsDiff too large to display app-page-tur..ntime.dev.jsDiff too large to display app-page-tur..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsDiff too large to display app-page-tur..time.prod.jsDiff too large to display app-page.runtime.dev.jsDiff too large to display app-page.runtime.prod.jsDiff too large to display 📎 Tarball URLCommit: c8fa288 |
React renders the most recently dispatched router state. A preempting navigation is dispatched after the actions it inherits from the displaced action, but settles before them, so the states those actions produce never render: the queue's internal state advances while the UI stays on the navigation's state until some later dispatch re-renders it. Most visibly, a revalidating action queued behind a navigation applies its refreshed data internally but the screen never updates. When the queue drains after a preemption, render the queue's state. At that point nothing is pending, so publishing a plain value cannot supersede an unsettled state promise, and it is published before any deferred refresh is dispatched so the refresh remains the newest state.
1638c86 to
c8fa288
Compare
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.
Claude noticed this while working on #95391.
Basically, the queue's React state always gets updated in the order of dispatching. So if a navigation displaced pending actions, it's the navigation's promise that was last. So when the pending action runs after it, that action's state is no longer taken into account, even if it revalidated. This is why the new data won't reflect on the screen.
With the fix, the final state is properly reflected.
Test Plan
New test, which was red before the fix.
Also tried it on a mini-app.
Before:
before.mov
After:
after.mov
How
We re-render at the end with the final queue state — if we know it was preempted.