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 the example, I found something strange (correct me if I'm wrong) about the state in client after calling getInitialProps in _document from the server.
We dispatch an async action on server to edit tack
// _document.jsstaticasyncgetInitialProps(ctx){constprops=awaitDocument.getInitialProps(ctx);const{store, isServer, pathname, query}=ctx;console.log(MyDocument.name,'- 2. Cmp.getInitialProps uses the store to dispatch things, pathname',pathname,'query',query);if(isServer){returnnewPromise((res)=>{setTimeout(()=>{store.dispatch({type: 'TACK',payload: 'server'});// <--- hereres(props);},200);});}store.dispatch({type: 'TACK',payload: 'client'});returnprops;}
So in the tack should be equal to server but it's equal to init.
It seems that you're hitting the known issue vercel/next.js#1267. Per Next.js authors it's better NOT to use _document for that purpose, use HOC instead.
Hello,
In the example, I found something strange (correct me if I'm wrong) about the state in client after calling
getInitialProps
in_document
from the server.We dispatch an async action on server to edit
tack
So in the tack should be equal to
server
but it's equal toinit
.Thanks for your help.
The text was updated successfully, but these errors were encountered: