Fix #439: handle chunk load failures by reloading the page

When a new version is deployed and old chunks are replaced, users
with the old HTML in-session will encounter "Loading chunk N failed"
errors on lazy-loaded routes. Add a router.onError handler to detect
these failures and reload the page so the browser fetches fresh HTML
and updated chunk manifests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Your Name 2026-02-20 21:42:59 -08:00
parent 6858a9ad67
commit 8e7c232c0c
1 changed files with 8 additions and 0 deletions

View File

@ -72,3 +72,11 @@ router.afterEach(() => {
// finish progress bar // finish progress bar
NProgress.done() NProgress.done()
}) })
router.onError((error) => {
const pattern = /Loading chunk (\d)+ failed/g
const isChunkLoadFailed = error.message.match(pattern)
if (isChunkLoadFailed) {
window.location.reload()
}
})