Skip to content

Commit

Permalink
Merge pull request #5559 from mc-zone/feature/jsonp-error
Browse files Browse the repository at this point in the history
Provide error type and request url when dynamic chunk failed to load (resolves #4595)
  • Loading branch information
sokra committed Sep 15, 2017
2 parents 2d84450 + 553287d commit 9e5765f
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 29 deletions.
17 changes: 14 additions & 3 deletions lib/JsonpMainTemplatePlugin.js
Expand Up @@ -66,9 +66,13 @@ class JsonpMainTemplatePlugin {
this.indent(`script.setAttribute("nonce", ${this.requireFn}.nc);`),
"}",
`script.src = ${this.requireFn}.p + ${scriptSrcPath};`,
`var timeout = setTimeout(onScriptComplete, ${chunkLoadTimeout});`,
"var timeout = setTimeout(function(){",
this.indent([
"onScriptComplete({ type: 'timeout', target: script });",
]),
`}, ${chunkLoadTimeout});`,
"script.onerror = script.onload = onScriptComplete;",
"function onScriptComplete() {",
"function onScriptComplete(event) {",
this.indent([
"// avoid mem leaks in IE.",
"script.onerror = script.onload = null;",
Expand All @@ -77,7 +81,14 @@ class JsonpMainTemplatePlugin {
"if(chunk !== 0) {",
this.indent([
"if(chunk) {",
this.indent("chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));"),
this.indent([
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
"var realSrc = event && event.target && event.target.src;",
"var error = new Error('Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')');",
"error.type = errorType;",
"error.request = realSrc;",
"chunk[1](error);"
]),
"}",
"installedChunks[chunkId] = undefined;"
]),
Expand Down
Expand Up @@ -8,7 +8,7 @@ a0bf69daa522fbf8540c.js 1.03 kB 0 [emitted]
ffed75a7125f4bffaa65.js 1.99 kB 4 [emitted]
1eb486d42a31b58c16de.js 1.03 kB 5 [emitted]
c0be493fc1372241e789.js 1.03 kB 6 [emitted]
b377816b50b5f53bb16f.js 7.75 kB 7 [emitted] main
b377816b50b5f53bb16f.js 8.13 kB 7 [emitted] main
abfb187b6140d9d3505a.js 1.99 kB 8, 0, 5 [emitted]
Entrypoint main = b377816b50b5f53bb16f.js
chunk {0} c659704b2f31cae80013.js 1.8 kB {7} [rendered]
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/chunks/expected.txt
Expand Up @@ -4,7 +4,7 @@ Time: Xms
0.bundle.js 288 bytes 0 [emitted]
1.bundle.js 152 bytes 1 [emitted]
2.bundle.js 232 bytes 2 [emitted]
bundle.js 6.43 kB 3 [emitted] main
bundle.js 6.82 kB 3 [emitted] main
chunk {0} 0.bundle.js 54 bytes {3} [rendered]
> [0] (webpack)/test/statsCases/chunks/index.js 3:0-16
[3] (webpack)/test/statsCases/chunks/c.js 54 bytes {0} [built]
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/commons-chunk-min-size-0/expected.txt
Expand Up @@ -2,7 +2,7 @@ Hash: e2982ecf41bd0a7eda73
Time: Xms
Asset Size Chunks Chunk Names
entry-1.js 81 bytes 0 [emitted] entry-1
vendor-1.js 7.5 kB 1 [emitted] vendor-1
vendor-1.js 7.89 kB 1 [emitted] vendor-1
[0] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/a.js 22 bytes {1} [built]
[1] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/b.js 22 bytes {1} [built]
[2] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/c.js 22 bytes {1} [built]
Expand Down
4 changes: 2 additions & 2 deletions test/statsCases/commons-plugin-issue-4980/expected.txt
Expand Up @@ -5,7 +5,7 @@ Child
Asset Size Chunks Chunk Names
app.js 1.33 kB 0 [emitted] app
vendor.76e65ef421e93d510398.js 493 bytes 1 [emitted] vendor
runtime.js 6.51 kB 2 [emitted] runtime
runtime.js 6.9 kB 2 [emitted] runtime
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
[./entry-1.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-1.js 67 bytes {0} [built]
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
Expand All @@ -16,7 +16,7 @@ Child
Asset Size Chunks Chunk Names
app.js 1.38 kB 0 [emitted] app
vendor.76e65ef421e93d510398.js 493 bytes 1 [emitted] vendor
runtime.js 6.51 kB 2 [emitted] runtime
runtime.js 6.9 kB 2 [emitted] runtime
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
[./entry-2.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-2.js 67 bytes {0} [built]
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/import-weak/expected.txt
Expand Up @@ -2,7 +2,7 @@ Hash: 00bdc9e68dab6471776c
Time: Xms
Asset Size Chunks Chunk Names
0.js 149 bytes 0 [emitted]
entry.js 6.54 kB 1 [emitted] entry
entry.js 6.93 kB 1 [emitted] entry
[0] (webpack)/test/statsCases/import-weak/modules/b.js 22 bytes {0} [built]
[1] (webpack)/test/statsCases/import-weak/entry.js 120 bytes {1} [built]
[2] (webpack)/test/statsCases/import-weak/modules/a.js 37 bytes [built]
6 changes: 3 additions & 3 deletions test/statsCases/limit-chunk-count-plugin/expected.txt
Expand Up @@ -16,7 +16,7 @@ Child
Time: Xms
Asset Size Chunks Chunk Names
0.bundle.js 651 bytes 0 [emitted]
bundle.js 6.44 kB 1 [emitted] main
bundle.js 6.83 kB 1 [emitted] main
chunk {0} 0.bundle.js 118 bytes {1} [rendered]
[1] (webpack)/test/statsCases/limit-chunk-count-plugin/a.js 22 bytes {0} [built]
[2] (webpack)/test/statsCases/limit-chunk-count-plugin/b.js 22 bytes {0} [built]
Expand All @@ -31,7 +31,7 @@ Child
Asset Size Chunks Chunk Names
0.bundle.js 504 bytes 0 [emitted]
1.bundle.js 232 bytes 1 [emitted]
bundle.js 6.43 kB 2 [emitted] main
bundle.js 6.82 kB 2 [emitted] main
chunk {0} 0.bundle.js 74 bytes {2} [rendered]
[1] (webpack)/test/statsCases/limit-chunk-count-plugin/a.js 22 bytes {0} [built]
[3] (webpack)/test/statsCases/limit-chunk-count-plugin/c.js 30 bytes {0} [built]
Expand All @@ -48,7 +48,7 @@ Child
0.bundle.js 232 bytes 0 [emitted]
1.bundle.js 254 bytes 1 [emitted]
2.bundle.js 333 bytes 2 [emitted]
bundle.js 6.42 kB 3 [emitted] main
bundle.js 6.81 kB 3 [emitted] main
chunk {0} 0.bundle.js 44 bytes {2} {3} [rendered]
[2] (webpack)/test/statsCases/limit-chunk-count-plugin/b.js 22 bytes {0} [built]
[5] (webpack)/test/statsCases/limit-chunk-count-plugin/e.js 22 bytes {0} [built]
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/named-chunks-plugin-async/expected.txt
Expand Up @@ -3,7 +3,7 @@ Time: Xms
Asset Size Chunks Chunk Names
chunk-containing-__a_js.js 316 bytes chunk-containing-__a_js [emitted]
chunk-containing-__b_js.js 173 bytes chunk-containing-__b_js [emitted]
entry.js 6.32 kB entry [emitted] entry
entry.js 6.7 kB entry [emitted] entry
[0] (webpack)/test/statsCases/named-chunks-plugin-async/modules/b.js 22 bytes {chunk-containing-__b_js} [built]
[1] (webpack)/test/statsCases/named-chunks-plugin-async/entry.js 47 bytes {entry} [built]
[2] (webpack)/test/statsCases/named-chunks-plugin-async/modules/a.js 37 bytes {chunk-containing-__a_js} [built]
2 changes: 1 addition & 1 deletion test/statsCases/named-chunks-plugin/expected.txt
Expand Up @@ -2,7 +2,7 @@ Hash: e2a3a4f76d4a30adbf3e
Time: Xms
Asset Size Chunks Chunk Names
entry.js 615 bytes entry [emitted] entry
manifest.js 6.52 kB manifest [emitted] manifest
manifest.js 6.91 kB manifest [emitted] manifest
vendor.js 469 bytes vendor [emitted] vendor
[0] multi ./modules/a ./modules/b 40 bytes {vendor} [built]
[./entry.js] (webpack)/test/statsCases/named-chunks-plugin/entry.js 72 bytes {entry} [built]
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/optimize-chunks/expected.txt
Expand Up @@ -8,7 +8,7 @@ Time: Xms
4.js 212 bytes 4, 6 [emitted] chunk
5.js 356 bytes 5, 3 [emitted] cir2 from cir1
6.js 130 bytes 6 [emitted] ac in ab
main.js 7.1 kB 7 [emitted] main
main.js 7.49 kB 7 [emitted] main
chunk {0} 0.js (cir1) 81 bytes {3} {5} {7} [rendered]
> duplicate cir1 from cir2 [6] (webpack)/test/statsCases/optimize-chunks/circular2.js 1:0-79
> duplicate cir1 [7] (webpack)/test/statsCases/optimize-chunks/index.js 13:0-54
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/performance-disabled/expected.txt
Expand Up @@ -3,7 +3,7 @@ Time: <CLR=BOLD>X</CLR>ms
<CLR=32,BOLD>0.js</CLR> 288 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 152 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 232 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>main.js</CLR> 306 kB <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> main
<CLR=32,BOLD>main.js</CLR> 307 kB <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> main
Entrypoint <CLR=BOLD>main</CLR> = <CLR=32,BOLD>main.js</CLR>
[0] <CLR=BOLD>(webpack)/test/statsCases/performance-disabled/index.js</CLR> 52 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
[1] <CLR=BOLD>(webpack)/test/statsCases/performance-disabled/a.js</CLR> 300 kB {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
Expand Down
6 changes: 3 additions & 3 deletions test/statsCases/performance-error/expected.txt
Expand Up @@ -3,7 +3,7 @@ Time: <CLR=BOLD>X</CLR>ms
<CLR=32,BOLD>0.js</CLR> 288 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 152 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 232 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>307 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
Entrypoint <CLR=BOLD>main</CLR> <CLR=33,BOLD>[big]</CLR> = <CLR=32,BOLD>main.js</CLR>
[0] <CLR=BOLD>(webpack)/test/statsCases/performance-error/index.js</CLR> 52 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
[1] <CLR=BOLD>(webpack)/test/statsCases/performance-error/a.js</CLR> 300 kB {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
Expand All @@ -15,10 +15,10 @@ Entrypoint <CLR=BOLD>main</CLR> <CLR=33,BOLD>[big]</CLR> = <CLR=32,BOLD>main.js<
<CLR=31,BOLD>ERROR in asset size limit: The following asset(s) exceed the recommended size limit (250 kB).
This can impact web performance.
Assets:
main.js (306 kB)</CLR>
main.js (307 kB)</CLR>

<CLR=31,BOLD>ERROR in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (250 kB). This can impact web performance.
Entrypoints:
main (306 kB)
main (307 kB)
main.js
</CLR>
2 changes: 1 addition & 1 deletion test/statsCases/performance-no-hints/expected.txt
Expand Up @@ -3,7 +3,7 @@ Time: <CLR=BOLD>X</CLR>ms
<CLR=32,BOLD>0.js</CLR> 288 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 152 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 232 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>307 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
Entrypoint <CLR=BOLD>main</CLR> <CLR=33,BOLD>[big]</CLR> = <CLR=32,BOLD>main.js</CLR>
[0] <CLR=BOLD>(webpack)/test/statsCases/performance-no-hints/index.js</CLR> 52 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
[1] <CLR=BOLD>(webpack)/test/statsCases/performance-no-hints/a.js</CLR> 300 kB {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/preset-detailed/expected.txt
Expand Up @@ -4,7 +4,7 @@ Time: Xms
0.js 288 bytes 0 [emitted]
1.js 152 bytes 1 [emitted]
2.js 232 bytes 2 [emitted]
main.js 6.42 kB 3 [emitted] main
main.js 6.81 kB 3 [emitted] main
Entrypoint main = main.js
chunk {0} 0.js 54 bytes {3} [rendered]
> [0] (webpack)/test/statsCases/preset-detailed/index.js 3:0-16
Expand Down
Expand Up @@ -3,7 +3,7 @@ Time: <CLR=BOLD>X</CLR>ms
<CLR=32,BOLD>0.js</CLR> 318 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 182 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 262 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>307 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
<CLR=32,BOLD>0.js.map</CLR> 291 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js.map</CLR> 250 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js.map</CLR> 404 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
Expand All @@ -18,10 +18,10 @@ Time: <CLR=BOLD>X</CLR>ms
<CLR=33,BOLD>WARNING in asset size limit: The following asset(s) exceed the recommended size limit (250 kB).
This can impact web performance.
Assets:
main.js (306 kB)</CLR>
main.js (307 kB)</CLR>

<CLR=33,BOLD>WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (250 kB). This can impact web performance.
Entrypoints:
main (306 kB)
main (307 kB)
main.js
</CLR>
6 changes: 3 additions & 3 deletions test/statsCases/preset-normal-performance/expected.txt
Expand Up @@ -3,7 +3,7 @@ Time: <CLR=BOLD>X</CLR>ms
<CLR=32,BOLD>0.js</CLR> 288 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 152 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 232 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>307 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
[0] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance/index.js</CLR> 52 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
[1] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance/a.js</CLR> 300 kB {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
[2] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance/b.js</CLR> 22 bytes {<CLR=33,BOLD>1</CLR>}<CLR=32,BOLD> [built]</CLR>
Expand All @@ -14,10 +14,10 @@ Time: <CLR=BOLD>X</CLR>ms
<CLR=33,BOLD>WARNING in asset size limit: The following asset(s) exceed the recommended size limit (250 kB).
This can impact web performance.
Assets:
main.js (306 kB)</CLR>
main.js (307 kB)</CLR>

<CLR=33,BOLD>WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (250 kB). This can impact web performance.
Entrypoints:
main (306 kB)
main (307 kB)
main.js
</CLR>
2 changes: 1 addition & 1 deletion test/statsCases/preset-normal/expected.txt
Expand Up @@ -4,7 +4,7 @@ Time: Xms
0.js 288 bytes 0 [emitted]
1.js 152 bytes 1 [emitted]
2.js 232 bytes 2 [emitted]
main.js 6.42 kB 3 [emitted] main
main.js 6.81 kB 3 [emitted] main
[0] (webpack)/test/statsCases/preset-normal/index.js 51 bytes {3} [built]
[1] (webpack)/test/statsCases/preset-normal/a.js 22 bytes {3} [built]
[2] (webpack)/test/statsCases/preset-normal/b.js 22 bytes {1} [built]
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/preset-verbose/expected.txt
Expand Up @@ -4,7 +4,7 @@ Time: Xms
0.js 288 bytes 0 [emitted]
1.js 152 bytes 1 [emitted]
2.js 232 bytes 2 [emitted]
main.js 6.42 kB 3 [emitted] main
main.js 6.81 kB 3 [emitted] main
Entrypoint main = main.js
chunk {0} 0.js 54 bytes {3} [rendered]
> [0] (webpack)/test/statsCases/preset-verbose/index.js 3:0-16
Expand Down

0 comments on commit 9e5765f

Please sign in to comment.