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
This is a question about how my app will work in production versus in next dev.
My app has the page /[...params].js.
I fetch data in chunks for the app, and use getInitialProps for the initial chunk which allows faster first-page-render. The rest of the data is fetched asynchronously from componentDidMount
I link between pages in the app, but always remain on /[...params].js while doing so. To suppress refetching the initial chunk on each page navigation, I check if(req) within getInitialProps to avoid calling the unwanted part when the client runs getInitialProps.
This works fine!
Unless I in development change something in the /[...params].js file. Then HMR kicks in. State/Props/this.variables are all cleared. Now, however, getInitialProps is run from the client, so I am unable to fetch the initial chunk this time...
So now the app crashes with an Unhandled Runtime Error further down the line.
My questions are:
In dev - is there a way in getInitialProps to discover that HMR happened, and to surpass the if(req) test only then?
In prod, and most importantly, are there scenarios where something similar could happen - that the state/props/this.variables are deleted and my app tries to refetch from getInitialProps but is denied since it tries to do so client-side? Or is this just a development issue?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
This is a question about how my app will work in production versus in
next dev
./[...params].js
.getInitialProps
for the initial chunk which allows faster first-page-render. The rest of the data is fetched asynchronously fromcomponentDidMount
/[...params].js
while doing so. To suppress refetching the initial chunk on each page navigation, I checkif(req)
withingetInitialProps
to avoid calling the unwanted part when the client runsgetInitialProps
./[...params].js
file. Then HMR kicks in. State/Props/this.variables are all cleared. Now, however,getInitialProps
is run from the client, so I am unable to fetch the initial chunk this time...So now the app crashes with an
Unhandled Runtime Error
further down the line.My questions are:
getInitialProps
to discover that HMR happened, and to surpass theif(req)
test only then?getInitialProps
but is denied since it tries to do so client-side? Or is this just a development issue?Beta Was this translation helpful? Give feedback.
All reactions