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

Error: This Suspense boundary received an update before it finished hydrating. #2

Open
Fabiantjoeaon opened this issue Jul 25, 2024 · 2 comments

Comments

@Fabiantjoeaon
Copy link

Hey! Thanks again for opening up your ecosystem of tools, this was just what I was looking for - as proper page transitions in React / Next.js with lifecycle hooks are far from trivial :)

I'm currently trying to implement this using Next.js like this:

function DefaultPageTransition({ children }) {
  const router = useRouter();

  // get a more friendly path name (especially for generic pages instead of [...slug])
  const pageName = router.asPath;

  return (
    <PageTransitions
      key={router.isReady ? "hydrated" : "ssr"} // make sure ?querystring parsing works
      pageName={pageName}
    >
      {children}
    </PageTransitions>
  );
}
<DefaultPageTransition>
            <Component key={router.asPath} {...pageProps} />
</DefaultPageTransition>

I get this error however:

Error: 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.

This happens in PageWrapper.tsx, I've tried the following, but to no avail:

useEffect(() => {
   startTransition(() => {
     store.setState({ suspendedRoute: pathname });
   });
   return () => {
     startTransition(() => {
       store.setState({ suspendedRoute: null });
     });
   };
 }, [pathname]);

I've also tried changing useEffect to useIsoMorphicLayoutEffect, but that won't help either.

@Fabiantjoeaon
Copy link
Author

I'm on Next.js v14.2.5 using the pages router

@ffdead
Copy link
Member

ffdead commented Sep 3, 2024

Hi @Fabiantjoeaon - sorry for the silcence, I somehow don't get an email on new issues, not sure what setting to adjust 🤔

Not exactly sure why this happens in your case, it's a bit delicate depending on the Nextjs version and order of components it seems.

For isntance, I've had this error happen when calling usePageTransition() as a hook in the layout component outside the component - but solved it by wrapping it in a functional component instead of just using the hook.

Sorry for not having more ideas!

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

No branches or pull requests

2 participants