You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In development mode on page refresh this error appears. It is related to this code in layouts/PageLayout/PageLayout.tsx:
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.
It's related to logged in user being fetched between two Suspense boundaries, and that user object affects states in child components, causing difference on client and server. It is enough to remove inner Suspense boundary to prevent the error. Another way to prevent it is to render null in MeProvider when useMe is in loading state, but that causes entire UI to flicker.
This error is easy to reproduce when query keys mismatch in prefetchQuery in getServerSideProps and client side useQuery. But some other state mismatch between client and server also causes this error, I wasn't able to determine which state mismatch exactly.
Here is the link of test case repository for reproduction:
// my-react-query/posts/usePosts.tsexportconstusePosts=()=>{constquery=useQuery<Post[],AxiosError>(['posts'],()=>getPosts());returnquery;};// 2.// pages/index.tsxexportconstgetServerSideProps: GetServerSideProps=async({ req, res })=>{constqueryClient=newQueryClient();awaitqueryClient.prefetchQuery(['posts'],()=>posts);};
To Reproduce
Start app in development mode, login as any user, go to profile or home page and refresh it few times, this error will appear. In production build it doesn't seem to appear.
Expected behavior
Error should not appear on page refresh.
Screenshots
Environment (please complete the following information):
Development or production app environment: development
Browser [e.g. chrome v60.12.0, safari 10.1]: both Chrome and Firefox
OS: [e.g. iOS, Windows x64] (if applicable): Ubuntu 20.04
node version (if applicable): v16.13.1
Additional context
Here is related issue in React repository but suggested solution to memoize children prop does not prevent error and just causes stale links in navbar.
Describe the bug
In development mode on page refresh this error appears. It is related to this code in
layouts/PageLayout/PageLayout.tsx
:It's related to logged in user being fetched between two Suspense boundaries, and that user object affects states in child components, causing difference on client and server. It is enough to remove inner Suspense boundary to prevent the error. Another way to prevent it is to render null in
MeProvider
when useMe is in loading state, but that causes entire UI to flicker.This error is easy to reproduce when query keys mismatch in
prefetchQuery
ingetServerSideProps
and client sideuseQuery
. But some other state mismatch between client and server also causes this error, I wasn't able to determine which state mismatch exactly.Here is the link of test case repository for reproduction:
https://github.com/nemanjam/hydration-test-case
To Reproduce
Start app in development mode, login as any user, go to profile or home page and refresh it few times, this error will appear. In production build it doesn't seem to appear.
Expected behavior
Error should not appear on page refresh.
Screenshots
Environment (please complete the following information):
Additional context
Here is related issue in React repository but suggested solution to memoize children prop does not prevent error and just causes stale links in navbar.
facebook/react#24476 (comment)
The text was updated successfully, but these errors were encountered: