nuxt: Auto reload page when chunk assets are not found
References: nuxt/nuxt.js#14591
We had this feature in Nuxt 2. Basically what happens is with a new deployment, hashes of old js chunks will be changed. And if users already loaded the page with manifest and chunks of the last deployment, they fail when navigating on client-side that tries to load dynamic chunks.
There are several ways to resolve this issue but probably the safest and easiest, is that same as Nuxt 2 we make use of a global error handler that identifies such errors and reload pages. (Note for implementation: We should set a LocalStorage key to avoid infinity page reloads)
Bonus: We could new offer a new nuxtApp hook such as app:chunkError that allows graceful HMR alike handling by end-user.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 13
- Comments: 28 (7 by maintainers)
I hope to raise the priority of this function, For any enterprise adopting nuxt in the production environment, they does not want to see a page with all styles lost when the user opens the browser for the first time after each new deployment. Thanks @pi0
I keep old hashes on the CDN living for some time, but use a custom Nuxt module that detects app update and shows a notification suggesting to reload the page.
I have been using this approach for years (even since pre-bridge Nuxt 2) privately. Today I published the module as a reusable npm package: nuxt-update. Hope someone finds it useful, too. ✌️
Ok thank you for the clarification. 😃 On a side note, I’ve really loved working with nuxt3 and despite this major issue I’m running into, I’ve found it a joy to develop with.
It will be good to have information on which NuxtLink was clicked and then redirect to this URL when error occurs.
I’m so glad this has come up again! I didn’t realize it had been mentioned before because I’ve actually just discovered this issue and it has caused a huge pain for me and my users. Getting some eyes on this issue would be hugely appreciated 🙏
Hey, any news on this or perhaps a temporary workaround? Vercel in particular is annoying as they seemingly don’t store old chunks at all which results in them being interpreted as function calls…
I used the solution by @shiva-prasad-reddy and it works. Thanks a lot! I hope Nuxt 3 will soon handle this out of the box, because now the default behavior is that Nuxt apps can easily end up in an unrecoverable crashed state without any feedback to the user.
Hey guys, for my use case the following solution is working, hoping for a better and offical way to do this sooner.