Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This Suspense boundary received an update before it finished hydrating #35

Open
danilofuchs opened this issue Dec 26, 2023 · 12 comments
Open

Comments

@danilofuchs
Copy link

When adding <SpeedInsights /> component to our Next.js application, we receive this error on Sentry and locally:

This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual way to fix this is to wrap the original update in startTransition.

@wadehammes
Copy link

wadehammes commented Jan 10, 2024

Seconded. Here is video of the error, and then when I comment out <SpeedInsights />, it goes away.

https://www.dropbox.com/scl/fi/vuolccukqshpeqdxouwcq/Screen-Recording-2024-01-10-at-7.34.32-AM.mov?rlkey=x08vb60pk4nm3n88yzl53gznh&dl=0

Error:
image

I think it's worth noting that we are still using the pages directory.

@tobiaslins
Copy link
Collaborator

Hey all! Sorry for the inconvenience.

Can you please provide us a simple replication repository to dig into this? Thanks for your help!

@wadehammes
Copy link

wadehammes commented Jan 12, 2024

Hey all! Sorry for the inconvenience.

Can you please provide us a simple replication repository to dig into this? Thanks for your help!

I could give you temporary access to our repo potentially, but I don't have time to spend debugging this honestly.

I can note some things we use: React Query, pages directory, styled-components, dynamic imports, etc. you can see in my shared video above that it is most definitely the SpeedInsights component causing the hydration error. I'm assuming it's the Suspense component being used within pages directory, as I've ran into that before.

@tobiaslins

@wadehammes
Copy link

wadehammes commented Jan 18, 2024

Is there a bare minimum codesandbox for the pages directory? I am only seeing a codesandbox for the app router. Going to try and get something together because I am tired of seeing this issue.

Edit: please link it if there is

@wadehammes
Copy link

This was fun lol, spent all day trying to replicate by creating a small reproduction of our site in totality and by removing items from our build one by one to find a root cause. Found the culprit in our case, a hook we used that didn't handle an effect properly. Really wish the error had more info to deduce this easier, but glad to have figured it out! Sorry for the noise here.

@samuelcole
Copy link

this is happening to me as well: i'm getting the error message, and poking around the call stack reveals it occurs when rendering <SpeedInsights />, and sure enough, removing speed insights silences the error

i'm willing to accept that it might be caused by some other code, but speed insights is certainly a catalyst in some way

@samuelcole
Copy link

my app seems to change props.route rapidly on load, which triggers this effect:

i believe if that effect was a transition instead (or additionally), it would make react chill out a bit

i'm still investigating why app.route changes so often...

@samuelcole
Copy link

the other patch that might fix it for me (my two props.route changes are to the same string), is the script.dataset.route gets modified, even when the strings are equal, which creates an unnecessary dom change:

script.dataset.route = route ?? undefined;

it might also resolve it to wrap that in a check

    setRoute: (route: string | null): void => {
      if (route !== script.dataset.route) {
        script.dataset.route = route ?? undefined;
      }
    },

or you could put that check here:

} else if (props.route) {

else if (props.route && props.route !== currentRoute)

@andrejoaquim-bounce
Copy link

andrejoaquim-bounce commented Mar 6, 2024

I'm having the same issue but I can't reproduce it, it occurs only at times as I found it in our logs. Is there any solution for this?

Additional information:

  • Next.js 14.0.14
  • Pages router
  • <SpeedInsights /> is included in _app.tsx

@pavliukpetro
Copy link

Same issue for me with Next 14 and pages.
Added the SpeedInsights into _app.js

@akshitkrnagpal
Copy link

Hey all.

We were also facing the same issue with pages router in _app.js. This was happening because one of our providers was causing a re-render multiple times. For short term, I moved the <SpeedInsights /> component outside all providers. For long term, will be refactoring our provider to fix this properly.

Something like this.

export default function MyApp({ Component, pageProps }) {
  return (
    <>
      <Providers>
        <Layout>
          <Component {...pageProps} />
        </Layout>
      </Providers>
      <SpeedInsights />
    </>
  );
}

Hope this helps someone.

@mausworks
Copy link

mausworks commented Apr 21, 2024

Even moving <SpeedInsights /> outside the global providers and into a <React.Fragment> does not seem to solve this issue for our application using NextJS v13.5.6 and SpeedInsights 1.10.0.

Moving <SpeedInsights /> into _document.tsx does, however, seem to resolve this problem. Though, it will cause an error on the server instead.

EDIT: I managed to track down where the issue originated; as others have pointed out, it had to do with "bad effects". In this case, we accessed a global store in _app.tsx which was also updated shortly after rendering the page. Even though it resolved with the exact same value on the next render it still managed to cause issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants