fix(pages): keep previous page visible during lazy route transitions - #792
Merged
Merged
Conversation
Navigating to a lazy-loaded page (/benchmark, /quickstart, /docs, /blog) re-triggered the Suspense fallback — a plain black div — producing a black screen flash while the chunk downloaded. Route changes are now applied inside a React transition via a new useTransitionedLocation hook: <Routes> renders from a location that trails useLocation() by one startTransition, so a suspending route keeps the current page on screen until its chunk is ready. The black fallback still shows on first paint, preserving the intentional dark background on initial load. ScrollToTop now follows the displayed location, so the scroll reset happens when the new page actually appears. Fixes alibaba#788
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). |
14 tasks
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.
Fixes #788
Problem
Navigating to a lazy-loaded page (
/benchmark,/quickstart,/docs,/blog) re-triggered the<Suspense>fallback — a plain black<div>— so the whole page went black while the route's chunk downloaded.Approach
Approach 3 from the issue: keep the existing fallback for the true first-load case, but prevent it from showing during in-app transitions.
useTransitionedLocation()hook: returns a location that trailsuseLocation()by onestartTransition.<Routes location={...}>renders from it, so when the next route suspends, React keeps the current page visible (transition semantics) instead of unmounting to the fallback.ScrollToTopnow keys off the displayed location, so the scroll reset happens when the new page actually appears rather than while the old page is still on screen.<Routes>API on React Router 6.8.Acceptance criteria
npm test— 19/19 pass (5 files, including the new one)npm run lint— 0 errors (the 2 pre-existing warnings inHeroSection.tsx/MarkdownRenderer.tsxare untouched);tsc --noEmitclean