How to prevent additional re-renders due to params on NextJS?

I’m setting up a generic loading strategy for NextJS apps using framer-motion.

function MyApp({ Component, pageProps, router }) {
    const [isFirstMount, setIsFirstMount] = useState(true);

    useEffect(() => {
        const handleRouteChange = () => {
        };"routeChangeStart", handleRouteChange);

        // If the component is unmounted, unsubscribe
        // from the event with the `off` method:
        return () => {
  "routeChangeStart", handleRouteChange);
    }, [router]);
    console.log("My App ran");
    return (
            <AnimatePresence exitBeforeEnter>
                <motion.div exit={{ opacity: 0 }}>
                    {isFirstMount && <InitialTransition />}

I ran into an issue with params. When using params during initial loading (such as clicking on the refresh button on browser), NextJS loads an additional time. I believe its due to NextJS’s router query object update. For example, // works - you will see the black loading screen, the black loading screens slides down, and the child objects start popping on
// vs // fails - you will see the black loading screen flash in and out of view before the rest of the app proceeds

I made a codesandbox sample. On the browser side, test by adding or removing ?test=test to the end of the url.

How can I prevent the additional re-render or get the loader to work the same way regardless of having a param or not?

179 thoughts on “How to prevent additional re-renders due to params on NextJS?”

  1. Thank you for every other excellent article. Where else could anybody get that kind of info in such an ideal method of writing? I have a presentation subsequent week, and I’m at the look for such information.

  2. Do you have a spam problem on this website; I also am a blogger, and I was
    wanting to know your situation; we have developed
    some nice procedures and we are looking to swap methods with other folks, please shoot me an email if

  3. Every weekend i used to go to see this web page, as i wish for enjoyment,
    for the reason that this this web site conations genuinely good funny stuff too.

  4. Excellent post. I was checking constantly this weblog and
    I’m impressed! Very useful info particularly the closing part 🙂 I maintain such information a lot.
    I was seeking this particular info for a very long time.

    Thank you and good luck.

  5. Hello! This is kind of off topic but I need some guidance from an established blog. Is it very hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about making my own but I’m not sure where to start. Do you have any points or suggestions? Many thanks

  6. Pingback: zanaflex price
  7. Pingback: nolvadex coupon
  8. Pingback: olumiant 4 mg
  9. Pingback: olumiant price usa
  10. Pingback: merck covid drug
  11. Heya just wanted to give you a quick heads up and let
    you know a few of the images aren’t loading correctly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers and both show the same results.

  12. An attention-grabbing dialogue is price comment. I think that it’s best to write more on this topic, it might not be a taboo topic but generally persons are not sufficient to talk on such topics. To the next. Cheers

  13. i need a loan now direct lender, i need a loan low interest. i need loan to start the business need loan need a loan online i need easy loan, 24 hr cash advance loans, cash advance loans, cash advance, online cash advance loans unemployed. Business is typically viewed banking, provides business loans.

  14. Good blog! I really love how it is simple on my eyes and the data are well written. I am wondering how I could be notified when a new post has been made. I’ve subscribed to your RSS which must do the trick! Have a nice day!

  15. Hi there I am so glad I found your webpage, I really found you by accident, while I was researching on Yahoo for something else, Nonetheless I am here now and would
    just like to say many thanks for a marvelous post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read it all at
    the moment but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read much more,
    Please do keep up the awesome jo.

  16. You really make it seem so easy with your presentation but I find
    this topic to be actually something which I think I would never understand.
    It seems too complicated and very broad for me.
    I’m looking forward for your next post, I will try to get the
    hang of it!

  17. I’m not sure where you’re getting your info, but good topic.

    I needs to spend some time learning more or understanding more.

    Thanks for wonderful info I was looking for this info for my mission.

  18. Heya! I know this is sort of off-topic however I needed
    to ask. Does running a well-established website like yours require a massive amount work?
    I’m brand new to blogging however I do write in my journal
    daily. I’d like to start a blog so I can share my personal experience
    and feelings online. Please let me know if you have any kind of ideas or tips for brand
    new aspiring blog owners. Appreciate it!

    My web-site; coupon

  19. This is really interesting, You’re a very skilled blogger.
    I’ve joined your rss feed and look forward to seeking more of your great post.

    Also, I have shared your site in my social networks!

  20. Hey there! This is my first visit to your blog! We are a group of volunteers and starting a new project in a community in the same niche.
    Your blog provided us beneficial information to work on. You have done a marvellous job!

  21. Terrific article! This is the kind of information that are supposed to be shared around
    the net. Shame on Google for now not positioning this post
    higher! Come on over and seek advice from my website . Thank you

  22. pg ยอดเยี่ยมเกมออนไลน์สล็อตบนมือถือแบบใหม่ปัจจุบันของโลกสมัครเล่น PG SLOT วันนี้ไม่มีเบื่อไม่ซ้ำซากในแบบการเล่นเดิมๆอีกต่อไปเป็นเกมสล็อตที่แจ๊คพอตแตกหลายครั้งที่สุดลองเลย


Leave a Comment