Skip to content
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

emit an event when there are errors loading/preloading chunks #12080

Closed
4 tasks done
danielroe opened this issue Feb 16, 2023 · 8 comments · Fixed by #12084
Closed
4 tasks done

emit an event when there are errors loading/preloading chunks #12080

danielroe opened this issue Feb 16, 2023 · 8 comments · Fixed by #12084
Labels
enhancement New feature or request

Comments

@danielroe
Copy link
Contributor

Description

I would love to be able to catch errors when preloading chunks (which often occurs when a new deployment has taken place) so that I can handle thiings appropriately.

Suggested solution

This is how we've implemented within Nuxt:

https://github.com/nuxt/nuxt/pull/19038/files#diff-7860a08e52b47fe432d19a402b062801774cefbb935172e30ce1e83a1ec6a962

Alternative

No response

Additional context

I would be very happy to implement this within Vite. It's a relatively small (and non-breaking) change

Validations

@patak-dev
Copy link
Member

I think it would be better to move this upstream, so you don't need to rely on __vitePreload and other frameworks could benefit. If you have already an idea for the PR, maybe it is easier to discuss it there. I don't know if you are thinking of a standard way to handle these errors in Vite or if you would like to propose a way to configure this.

@patak-dev patak-dev added enhancement New feature or request and removed enhancement: pending triage labels Feb 16, 2023
@danielroe
Copy link
Contributor Author

I'll submit a PR. I would suggest solely emitting the event and leaving it up to frameworks/users to handle the reload (or not) as they would like.

@doutatsu
Copy link

This would be amazing, looking into Nuxt change. I got a ton of errors like these, which with end-user results in a blank screen, making them think the app is broken / down. Would love to see this released

image

@patak-dev
Copy link
Member

Thanks for the heads up @doutatsu 👍🏼

@victorlmneves
Copy link

will it also solve "regular" failed dynamic imports? Because in my case, probably 99% are related to this and not chunks that no longer exists after a deploy :/

@edwh
Copy link

edwh commented Jun 6, 2023 via email

@danielroe
Copy link
Contributor Author

danielroe commented Jun 6, 2023

The PR adds an error event - it's up to you to handle it. You can see how we handle the chunk loading errors in Nuxt on route change.

Note that regular failed imports (ie. not chunk loading errors) will not trigger this error.

@victorlmneves
Copy link

Well for me the strange is that Vue has functionality that when working with dynamic imports allows you to set a number of retries automatically but nevertheless even doing the retries it always fails when executing the import.
Meanwhile, we also have a person working on the migration of the project to Nuxt, then we will see how it will behave

e.g:

import { defineAsyncComponent } from 'vue';
import LoadingComponent from '../components/LoadingComponent/LoadingComponent.vue';
import ErrorComponent from '../components/ErrorComponent/ErrorComponent.vue';

 export const useComponent = (name: string) => {
    return defineAsyncComponent({
        loader: () => import(`../components/${name}/${name}.vue`),
        loadingComponent: LoadingComponent,
        errorComponent: ErrorComponent,
        delay: 2000,
        timeout: 3000,
        onError(error, retry, fail, attempts) {
            if (error.message.match(/fetch/) && attempts <= 3) {
                retry()
            } else {
                fail()
            }
        }
      })
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants