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): enable chunk error handling by default #19086
Conversation
Β Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
I tried it out, and I like it! Specifically I'm trying to handle the situation where the network connection is interrupted. This especially can happen often in corporate environments with VPNs. Without any handling, interrupted connections with Nuxt 3 result in a fatal error that is non-recoverable, i.e. any subsequent clicks when the connection is restored won't do anything. This is because of chunk loading errors. The user will not see this, but simply notice that interacting with the website is impossible. This is difficult because throwing an error will result in an error, due to Nuxt not being able to dynamically load the error component. I simulate this behavior by setting the throttling to "No connection" in the network tab in Chrome developer tools.
|
@mcrapts Would you explain more about this:
The |
Yes, exactly. Then I can differentiate between prefetch and navigation errors. Navigation errors are more critical and I want to handle them differently. |
Interesting idea. Currently we get that information this way in the export default defineNuxtPlugin((nuxtApp) => {
const router = useRouter()
const chunkErrors = new Set()
router.beforeEach(() => { chunkErrors.clear() })
nuxtApp.hook('app:chunkError', ({ error }) => { chunkErrors.add(error) })
router.onError((error, to) => {
if (chunkErrors.has(error)) {
// it was a navigation error
}
})
}) We can't really annotate the error (which is emitted from vite's preload function) without adding runtime code to do so, so that might be a future issue/PR. |
+1 to adding the ability to suppress chunk errors. Currently, depending on the caching strategy you have setup, new deployments will break the app until the page cache is cleared. The reason being that the cached pages will try to call JS chunk files that no longer exist. It would be good to simply suppress these errors while the cache is cleared and rebuilt. Does anyone know of a hacky way to do this before this feature is added? |
Would it be possible to extract it as a vite plugin for use in vite base SPA applications @danielroe |
Indeed. I've already opened a PR as the first step: vitejs/vite#12084 |
@danielroe Is there a rationale for only handling errors on the route? If you're using async components then you'll hit missing chunks when deploying on something like Netlify, where the old chunks are gone. Would the solution to that be to always reload when you hit a chunk error, along the lines of:
I've not tested this - I'm wondering if I'm missing something Very Bad that might happen. |
No, I think that should be a reasonable approach π |
@danielroe Thanks. I need to get the current path, which I can't get from
|
Try getting the route outside the hook - i.e. in the body of the plugin? You can also directly use |
@danielroe Thanks, I think that now works. But I think we might be able to do better, at least on Netlify. I've opened a separate issue #20950. |
π Linked issue
#19038 (comment)
#14594
resolves #19182
β Type of change
π Description
This is the next step to enabling chunk error handling by default in Nuxt apps.
Progress
reloadNuxtApp
composable.experimental
flag for emitting errors (and enable reload strategy by default)reload
strategy in Error Handling docs sectionFuture enhancements
π Checklist