Next.js: Reload after new deployment

Created on 10 Nov 2018  路  9Comments  路  Source: vercel/next.js

Here is a quote from deployment wiki

We generate a unique BUILD_ID for each time when you run next build. We use that id to detect new versions from the client side. If the client side app detects a new BUILD_ID it'll reload the page. With that, your users will use the latest version of your app always.

Client side doesn't reload automatically after new deployment. Should I do any extra config or something to enable it?

Thank you.

Most helpful comment

If the page is prefetched we don't do another call for the script bundle. If you want to handle this case you'll have to implement your own update loop using an interval to check if the buildId changed or something.

All 9 comments

The way it works is that the previous build bundles shouldn't be served anymore when there's a new version, meaning that the user will automatically get their page refreshed and they'll be on the new version.

@timneutkens My question might be stupid. Is there a way to update pages that are prefetched in the background? Once a new app version is deployed, a user clicks and loads a server-side rendered page and a new version is loaded to the user's browser. But this is not true for prefetched pages. If a user browses prefetched page, this user still browses older version of the app.

Thanks.

If the page is prefetched we don't do another call for the script bundle. If you want to handle this case you'll have to implement your own update loop using an interval to check if the buildId changed or something.

@tima101 "If a user browser prefetch page, this user still browser older version of the app."
you resolved those problem ?

@UsuJuan When we deploy new version of the app and when it does not match version on users' browsers - we use window.location.reload to reload tabs so all users with currently open tabs have most recent version of the app.

@tima101 Sorry for my next question, how to verify the change of BUILD_ID, can you show me an example, I'm starting in the programming. how know new version of the app and when it does not match version on users' browsers . Thanks in advance.

I have been struggling with this for a few days already.
Next custom production server does not pick up the new build until I completely restart the server.

@UsuJuan When we deploy new version of the app and when it does not match version on users' browsers - we use window.location.reload to reload tabs so all users with currently open tabs have most recent version of the app.

@tima101 do you use your custom version number or next.js BUILD_ID? I am trying to figure out how can I get latest build id pro zeit server.

@timneutkens I've been seeing an issue with our production next js app where after a new deployment, we usually track a Unexpected token '<' error being thrown. This seems to be caused by a call to router.push which triggers a request for a new page. All the app's pages are SSR.

Could the server be responding with an unexpected html error file? Any idea what this could be? I'm wondering if it is related to the client failing to reload and run the new deployed version. Could this be Next or is it more likely related to our deployment process having a small window where both our load balanced servers are offline.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

formula349 picture formula349  路  3Comments

YarivGilad picture YarivGilad  路  3Comments

sospedra picture sospedra  路  3Comments

lixiaoyan picture lixiaoyan  路  3Comments

olifante picture olifante  路  3Comments