-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Vite Async Module window onerror triggering capability #13755
Comments
Thank you very much for your reply. I carefully read the code submission you provided. From the source code, it seems that vite:preloadError only works for CSS file loading. Based on the element's hook, I was able to intercept addEventListener's error and load events to achieve retry capability. For asynchronously loaded module modules (non-preload), it is currently not possible to trigger exceptions and retries globally. One solution I can think of is to change the way Vite packages modules by replacing the asynchronous loading of import with a custom loadAsyncModule. My idea is to see if it is feasible to use the script method instead of asynchronous import. If it is feasible, it could be a common solution for Vite configuration. |
is there any update on this issue? |
No, it does work for JS as well (it had a bug though #15203). I'll close this issue as this is already implemented by #12084 |
Description
Background: We have a scenario where we need to retry resource loading when there are exceptions, such as when changing domain names, based on Vite packaging.
Problem: In Vite ESM packaging, dynamic imports cannot trigger
window.onerror
, making it impossible to listen for errors. For example, dynamic imports in router or code (dynamic imports under ESM can only go through the catch process).However, in webpack packaging, it will be loaded in the form of a script tag, and I will get
onerror
, thereby achieving the ability to retry.Suggested solution
The solution should be globally supported during construction to reduce the complexity of modifying the business side.
When Vite is built under ESM, it converts dynamic imports into script module loading and callback processing, which will not affect the original logic.
Alternative
No response
Additional context
If there are any unclear points, please let me know and I will supplement them.
Validations
The text was updated successfully, but these errors were encountered: