How to avoid blinking when switching between pages using react-router?
See original GitHub issue💬 Questions and Help
Hi,
Here is the problem:
When the page just loads, it causes blinks (or flashes) while navigating the pages. But after visiting the page for the first time it works smoothly.
How to make it work smooth always?
I tried to add webpackPrefetch: true
but this doesn’t help.
Here is the repo for reproduce https://github.com/ashgaliyev/react-router-loadable-components-flashing-problem
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Flashing screen when changing route with Reactjs
I have a simple route system, where I have a page as a Container ( Home Page ) and inside it I have...
Read more >Trying Lazy Loading and getting flicker? - DEV Community
It's "flashing" because you're page is loading too quickly, so the spinner loads and then disappears because the job is over. I'm not...
Read more >Getting an annoying flickering when navigating ... - Reddit
I have done similar sites using plain react and router and never had this problem before, this is the first time I'm seeing...
Read more >Flickering/Black glitch while redirecting to some other page
Hey there, We decided to go with ionic react for our patient ... fallback route causes flicker transition when routing between pages ·...
Read more >Tutorial v6.6.1 - React Router
In web semantics, a POST usually means some data is changing. By convention, React Router uses this as a hint to automatically revalidate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, the “real” fix would be to use
useTransition
andSuspense
from the experimental branch of React, so you will be able to “block” transition until the new page is ready.But that’s “experimental” today, and there is not much you can do.
However, you can try preventing navigation event manually and replaying it once page is ready to accept transition. Probably react-router would be not a best choice in this case.
The way I solved this is by not using loadable-components but rather React.lazy and dynamic imports
While your routes are React.lazy’d
Link to a page:
Hope this helps