-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nuxt): add experimental app:chunkError
hook and reload strategy
#19038
Conversation
Β Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
const router = useRouter() | ||
|
||
let chunkError: TypeError | null = null | ||
nuxtApp.hook('app:chunkError', ({ error }) => { chunkError = error }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also catch this directly here:
nuxtApp.hook('app:chunkError', ({ error }) => { chunkError = error }) | |
nuxtApp.hook('app:chunkError', ({ error }) => { | |
if (nuxtApp._processingMiddleware) { | |
// handle error here | |
} | |
}) |
I've not done that here in case the user has handled the error, but it's worth keeping in mind if someone has a better idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Nice work! For me it even looks good to be out of experimental flag testing on edge only. One note about implementation it would be nice if the "reload" functionality extracted as a composable utility |
Co-authored-by: pooya parsa <pyapar@gmail.com>
Great! π I think we can include in next minor, along with extracting reload helper. π For now I'll keep it under flag so we can merge in a patch release. |
app:chunkError
hook and experimental reload strategyapp:chunkError
hook and reload strategy
@danielroe so this is how I can set it in
Is that correct? |
@scofield-ua The API changed a little bit in #19086. The jsdocs should give the possible configuration options for this. It is enabled by default in v3.3+. |
π Linked issue
resolves #14594
β Type of change
π Description
This PR adds a feature that can be enabled with the
experimental.emitRouteChunkError
option. This will catch chunk loading errors and calls theapp:chunkError
page. This can be handled with something like this:You can also set
experimental.emitRouteChunkError
toreload
to enable an automatic hard reload when navigating if the new route triggers a chunk loading error.Notes:
reload
strategy does not handle all chunk errors, just ones on route navigation. For example, issues with prefetching chunks won't reload the page, though the error will still be thrown and it's possible to handle this intentionallyπ Checklist