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
[WIP] catch jsonp error #692
Conversation
a0c378e
to
97b1685
Compare
|
|
This reverts commit 97b1685.
6ab3165
to
6fb6c3b
Compare
@sokra ? |
I can take a look this evening... |
/******/ script.onload = script.onreadystatechange = function() { | ||
/******/ var readyState = this.readyState; | ||
/******/ if (!readyState || readyState === "loaded" || readyState === "complete") { | ||
/******/ end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the requirejs docs they reckon older IE's will call the onreadystatechange
handler with this.readyState
set to 'complete' even if the script 404'd. I haven't got access to IE to try this out at the moment but I think it might be worth testing this and as a potential fix check for installedChunks[chunkId] === 0
as you can be sure the script has downloaded successfully if the jsonp callback has been run.
This plugin looks really good, something I'm in need of. I wonder however if AMD support could be added without too much difficulty as, imo, AMD lends itself to error handling better than commonJS using this: require(['a'], function(a) {
// success
}, function() {
// error
}); I also wonder if it would be better to follow a similar signature for commonJS as that way it wouldn't be a breaking change: require.ensure(['a'], function(require) {
var a = require('a');
// success
}, function() {
// error
}); The only slight complication would be the need to check the type of the third argument to determine if it's the 'name' or an error callback. |
/******/ if (error) { | ||
/******/ installedChunks[chunkId] = -1; | ||
/******/ chunkLoadErrors[chunkId] = error; | ||
/******/ var callbacks = installedChunks[chunkId]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work as you set installedChunks[chunkid]
to -1
then try to retrieve the callbacks right after?
At work, I use a similar plug-in, but with a few changes. I saved the default order on arguments in require.ensure callback function for backward capability with webpack loaders and notify about As for the interface require.ensure, I have come to believe that the best way is to return the Promise, but i don't know what to do for old browsers. |
I personally am not so keen for promises in this situation as it's a massive departure from "standard" commonJS and AMD specifications. I think I've noticed require.async uses this format too. It'd be good to see what you're using currently. |
looks great... and this way we could keep backward compatiblity... |
I've sent a pull request which adds support for the error callback when using |
Any progress on this? I could use that too... |
I wrote a plugin https://github.com/richardscarrott/require-error-handler-webpack-plugin which adds error handling to |
Would be really useful if this merged |
@indianburger as a temporal solution you could use this: https://github.com/NekR/async-module-loader |
I've sent a pull request which adds support to Webpack v2.2 for the error callback when using require.ensure |
Here pull request for #686