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
I'm following the guide here to setup NextJS with Hydration. I can confirm that my dehydrated state is being passed correctly through page props, however on the first SSR render for my page component the hydrated state does not seem to be present. data is undefined and my component breaks as I depend on it to be loaded initially.
exportdefaultfunctionApp({ Component, pageProps }){// console.log here confirms dehydrated state exists and data has been populatedreturn(<React.Fragment><QueryClientProviderclient={queryClient}><Hydratestate={pageProps.dehydratedState}><Component{...pageProps}/></Hydrate></QueryClientProvider></React.Fragment>);}
exportasyncfunctiongetServerSideProps(context){const{query: { id }}=context;constqueryClient=newQueryClient();constapi=getAPI(context);awaitapi.reAuthenticate();awaitqueryClient.prefetchQuery(['resources',id],()=>api.getResource(id));return{props: {dehydratedState: dehydrate(queryClient)}};}
exportdefaultfunctionComponent(){constrouter=useRouter();// user query client confirms here that dehydrated data is not presentconst{ data }=useQuery(['resources',router.query.id],()=>getAPI().getResource(router.query.id));// breaks because data is not loaded initiallyreturn(<div>{data.id}</div>);}
Activity
lynxtaa commentedon Jan 17, 2021
It works in react-query@3.5.13, doesn't work in 3.5.14.
Maybe because of this PR #1643 ?
TkDodo commentedon Jan 17, 2021
possibly. I was raising that concern in the origin discussion here:
#1641 (reply in thread)
RickEyre commentedon Jan 17, 2021
Ah I see. Yes that would break it, I think, as useEffect is not run during SSR in NextJS.
tannerlinsley commentedon Jan 17, 2021
Fixed with eb3d700
RickEyre commentedon Jan 17, 2021
Thanks everyone.