question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to avoid blinking when switching between pages using react-router?

See original GitHub issue

💬 Questions and Help

Hi,

Here is the problem: Screen Recording 2020-01-14 at 03 39 PM 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
theKasheycommented, Nov 2, 2020

Well, the “real” fix would be to use useTransition and Suspense 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.

0reactions
hjoelhcommented, Aug 26, 2022

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:

    <a
      href='/dashboard'
      onMouseEnter={() => import('pages/dashboard')} // this is like a prefetch
      onClick={(e) => {
        e.preventDefault();
        import("pages/dashboard").then(() => { // waits for import before navigating (no spinners/fallback)
          navigate("/dashboard");
        });
      }}
    />

Hope this helps

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found