fix: startTransition in popstate should not show Suspense fallback#35975
Open
fresh3nough wants to merge 1 commit intofacebook:mainfrom
Open
fix: startTransition in popstate should not show Suspense fallback#35975fresh3nough wants to merge 1 commit intofacebook:mainfrom
fresh3nough wants to merge 1 commit intofacebook:mainfrom
Conversation
When startTransition is called inside a popstate event handler, the popstate eager transition path adds an artificial SyncLane to the render lanes. This caused includesOnlyTransitions() to return false, which prevented the suspension from being handled like a normal transition - showing the Suspense fallback instead of keeping the previous UI visible. Add a flag (workInProgressRootIsEagerPopstateTransition) that tracks when the current render was initiated as a popstate eager transition. Use this flag in renderDidSuspendDelayIfPossible and finishConcurrentRender to treat the render like a transition despite the artificial SyncLane, falling back to async behavior when the component suspends. Fixes: facebook#35966 Signed-off-by: Ubuntu <[email protected]>
|
Comparing: 4610359...7ad96ed Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
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.
Summary
When
startTransitionis called inside apopstateevent handler and the component suspends inside a<Suspense>boundary, React incorrectly shows the fallback instead of keeping the previous UI visible.Root Cause
The popstate eager transition path in
getNextLanesToFlushSyncadds an artificialSyncLaneto the render lanes as a priority marker. This causesincludesOnlyTransitions()to returnfalse, which breaks two critical checks:renderDidSuspendDelayIfPossible()does not setworkInProgressRootIsPrerendering = true, sorenderRootSyncdoes not yield when the shell suspendsfinishConcurrentRender()commits the fallback forRootSuspendedWithDelayinstead of suspending indefinitelyFix
Add a flag (
workInProgressRootIsEagerPopstateTransition) that tracks when the current render was initiated as a popstate eager transition. This flag is used alongside the existingincludesOnlyTransitions()check in:renderDidSuspendDelayIfPossible: enables prerendering mode sorenderRootSyncyields when the shell suspendsfinishConcurrentRender: prevents committing the fallback, falling through toRootSuspendedAtTheShellbehaviorThis ensures the popstate transition falls back to normal async transition behavior when it cannot complete synchronously.
Test Plan
Added a new test case
popstate transition with Suspense boundary should not show fallbackthat verifies:All existing popstate, Suspense, and transition tests continue to pass.
Fixes #35966