-
Notifications
You must be signed in to change notification settings - Fork 48
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
Reload of CSS-Chunks #2
Comments
If there's a hook in webpack to do it then it should be possible, I had a quick look and couldn't see anything though. I don't actually use this plugin anymore as I switched to a service worker (so everything is pre-loaded and resilient to the network going down), so it's not something I would be able to work on myself, but I'd be happy to review a PR. You might be able to fix your issue by doing this with your dynamic imports: https://webpack.js.org/guides/code-splitting/#prefetchingpreloading-modules or using a service worker: https://github.com/NekR/offline-plugin |
@mattlewis92 In the mean time, I'm using Service Workers too, and some first-time visitors still get ChunkLoadErrors, I assume simply because of network problems. Affected are chunks which are loaded directly by launching the web app. And since the browser was able to download other files just milliseconds before (e.g. the index.html) and since it's able to send a bug report, I assume it's just a temporary problem. In the documentation of the recommended offline-plugin, they write:
So I think your plugin would still as useful as before. Or do you think there would be changes required to better interact with service workers? |
One workaround I've found for this problem is to listen to the global error event and then use that to re-add stylesheets yourself, it seems to fix these types of errors in our logs. You could tweak the logic a bit to add multiple retry support and delays:
|
@mattlewis92 In my case I use mini-css-extract-plugin to extract the css to a chunk file. in sometimes the css request will got connection reset error. and I saw the mini-css-extract-plugin source code: Template.indent([
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
'var realHref = event && event.target && event.target.href || fullhref;',
'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + realHref + ")");',
'err.code = "CSS_CHUNK_LOAD_FAILED";',
'err.type = errorType;',
'err.request = realHref;',
'delete installedCssChunks[chunkId]',
'linkTag.parentNode.removeChild(linkTag)',
'reject(err);',
]) as you can see,this plugin just reject the error and no retry. in this case I will got the error Failed to load resource: xxxx.css net::ERR_CONNECTION_RESET
Uncaught (in promise) Error Loading CSS chunk 5 failed. in the main.js if this plugin can solve this problem ? |
Would it be possible to extend this plugin to also reload non-JS-chunks?
e.g. sometimes in my webapp, users get errors for CSS-Chunks:
Very often, these are timeout errors because of a bad internet connection.
The text was updated successfully, but these errors were encountered: