❓ How to prevent blank page flash during initial router mount? (with solution) #4554
Unanswered
jitesh-speakap
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The Problem I Encountered
I'm using TanStack Router with
beforeLoad
for authentication and data fetching, but I'm experiencing a blank page flash during initial app load. The sequence is:pendingComponent
shows duringbeforeLoad
What I Tried First
I thought
defaultPendingComponent
would solve this:But I still got the blank page flash.
Root Cause Analysis
After digging into the source code, I found the issue occurs in the
MatchesInner
component:The lifecycle gap:
RouterProvider
mounts →MatchesInner
rendersnull
Transitioner
callsrouter.load()
inuseLayoutEffect
(next tick)My Solution
I implemented a router state-based loading wrapper:
This completely eliminates the blank page flash! 🎉
My Questions
Is there a built-in way to handle this that I missed?
Is my solution the recommended approach, or is there a better pattern?
Should TanStack Router handle this internally? It seems like a common UX issue for apps with async
beforeLoad
operations.Would a
defaultMountingComponent
option make sense for the router to show during this pre-loading state?Context
This affects any app using:
beforeLoad
beforeLoad
beforeLoad
My setup:
Reproduction
The issue is reproducible with any app that has async
beforeLoad
operations. The blank page is brief but noticeable.Here's a short recording to help you understand:
Screen.Recording.2025-07-01.at.14.19.27.mp4
Beta Was this translation helpful? Give feedback.
All reactions