Facing hydrating problems after updating to 9.0 #536
-
Hi, I added this as a discussion since I'm not sure whether this is a library problem or I lack some understanding of how things work in 9.0. My app relies heavily on MyApp.getInitialProps = wrapper.getInitialAppProps(
(store) => async (appContext) => {
store.dispatch(globalDataSlice.endpoints.getGlobalData.initiate());
await Promise.all(
store.dispatch(globalDataSlice.util.getRunningQueriesThunk())
);
const appProps = await App.getInitialProps(appContext);
return { ...appProps };
}
); And then in the app component itself I would have something like this: function MyApp({ Component, pageProps }) {
useGetGlobalDataQuery();
return (
<Fragment>
{/* Header which uses some parts of the global data */}
<Header />
<Component {...pageProps} />
{/* Footer which also uses some parts of the global data */}
<Footer />
</Fragment>
);
}
export default wrapper.withRedux(MyApp); I also had the Anyway, I updated to next-redux-wrapper 9.0 today. I followed the guide for updating. I've removed all manual hydration and usages of HYDRATE, I switched to function MyApp(...) {
const store = wrapper.useStore();
return <Provider store={store}>
<AppWrapper /> // And then inside the AppWrapper i call useHydrate, and all the data fetching hooks
</Provider>
} but it doesn't work. When the page loads there is an initial flash of unhydrated data in the header, and then in a few moments the data appears. As I've mentioned, this is only the case with the data that gets fetched through So, am I using something wrong or is there no good way to fetch data in app's getInitialProps and have it displayed immediately on the first render? Thanks in advance :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Well, sorry for potentially wasting someone's time, but it seems I just accidentally put the function AppWrapper(...){
const globalData = useSelector(...);
wrapper.useHydration(...); // should be at the top
} which caused the globalData to be empty on the first render. |
Beta Was this translation helpful? Give feedback.
Well, sorry for potentially wasting someone's time, but it seems I just accidentally put the
useHydration
call after the selectors that extract the global data in myAppWrapper
:which caused the globalData to be empty on the first render.