-
-
Notifications
You must be signed in to change notification settings - Fork 2k
bug: Failed to fetch dynamically imported module after internet reconnect #13655
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
Comments
Unfortunately there's not much we can do, this (for some insane reason) is the expected behavior for dynamic imports according to the spec - the result of the import is cached, even if it was unsuccessful. There's talks to change that but that might take a while. Until then I'm not sure how we could mitigate this. One option would be to use query parameters to break the cache, but I'm not sure right now how much of this is Vite and if we can hook into this. |
I guess a solution is to use the "single" or "inline" bundleStrategy |
Would it be possible for SvelteKit/Vite to detect that a dynamic import failed, and then add the query parameter to break the cache? Or would cache have to be broken every time? |
After changing our bundleStrategy to "inline" we have stopped seeing these errors. The downside is that this has a big impact on initial load time, but we have decided that it's better to have our app load as expected. @dummdidumm do you know if loading JS scripts without type="module" also has the same caching of unsuccessful responses? If not, would it then be possible to have a bundleStrategy that splits the code without using type="module"? I've looked at how Figma loads their JS, and based on the source code of their HTML it seems that they do not use type="module", and load their JS separately through "basic" script tags. It would be great to have a bundle strategy that avoids the current pitfall of type="module" and at the same time has a better initial load than bundling everything inline. |
Describe the bug
If the user encounters an error while loading a page, for example due to missing internet connection, the page keeps erroring even when the user has regained internet connection. This makes it so that the user has to refresh the page in order to access the page since its broken in their current application state.
This issue causes the application to always throw the
TypeError: Failed to fetch dynamically imported module:
error every time the user tries to navigate to the broken route. The only way we have managed to fix the issue is by refreshing the browser tabReproduction
Steps to reproduce:
This behavior can be tested on this deployed application here which was deployed from this minimal reproduction. A gif showing how I'm able to trigger the error can be seen below
We have not been able to reproduce the bug without having it deployed since this reproduction relies on internet connection and remote requests.
Skjermopptak.2025-03-31.kl.12.12.09.mov
Minimal repro: https://github.com/AndersRobstad/svelte-network-error
Deployed application: https://svelte-network-error.vercel.app/
Logs
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: