Repository navigation
Commit 0f7ee78
authored
fix: name chunk imports in the chunk loader (#22076)
* fix: name chunk imports in the chunk loader
Baking a literal `import("./chunk.<hash>.js")` at every dynamic import site put the
imported chunk's content hash into the importing module, so a change to a lazily
loaded route invalidated every chunk on the path up to the initial wave — and the
chunk id to filename map in the runtime chunk stored the same hashes a second time.
The ESM chunk loader now holds the literal specifiers itself, keyed by chunk id, and
`.f.j` imports one instead of building a url from `.p + .u(id)`. Call sites go back
to `ensureChunk(id)`, so no importing module carries a chunk hash, the id to filename
map is not emitted where the loader names everything, and the output stays walkable:
every emitted chunk is still reached by a literal specifier a foreign bundler or a
preload scanner can follow. `__webpack_require__.ei` is gone with the call-site form.
Two bailout reasons moved with the decision: an output that cannot use a native
`import()` is reported where the imports are generated, and a runtime reading its
chunks another way reports from the chunk loader that will not serve it.
Closes #22056
* fix: keep the loader's url fallback for ids its map cannot hold
A chunk carrying a runtime of its own is reached by a static import and is never
named in the map, so a runtime that can reach one keeps building a url from the
chunk id; a hot update can force-load an id this build never saw, so HMR keeps it
too. Everything else imports the literal the map holds and emits no id table.
Naming an initial chunk there was the other half of this: it made that chunk's hash
and the loader's chase each other, and the pair settled with the entry shipping new
bytes under the content hash it already had.
* fix: report a chunk loading that is not import only when it is not
`reportChunkImportBailout` recorded the reason whatever the chunk loading was. Its
one caller asks only for a chunk the ESM loader does not serve, so nothing wrong
reached a build — but the method now answers for itself.
The unit tests asked `supportsAnalyzable` for a worker's chunk loading, which the
chunk loader decides now; they ask the reporting method instead.
* fix: reach the url fallback for a chunk a second entrypoint has at startup
One `runtimeChunk` in front of two entrypoints makes a split chunk initial for
the first and loadable by the second, so the loader's map leaves it unnamed
while an id for it still arrives. Ask whether such a chunk can be loaded here
rather than assuming an initial one never is.
Also wrap `map`'s callback in the context module, whose index would otherwise
be read as a fetch priority, and move the specifier shape to `util/identifier`.
* test: read the chunk names inside the loader's map
A name matched anywhere in the chunk let a test pass while the map itself was
missing the entry the loader indexes, so scope both checks to the map region
and name the deferred context's sync candidate alongside its async one.1 parent ec300ae commit 0f7ee78
79 files changed
Lines changed: 874 additions & 678 deletions
File tree
- .changeset
- lib
- esm
- runtime
- util
- test
- configCases
- analyzable
- block-origin-modules
- chunkhash-name-follows-fill
- circular-chunk-hashes-repaired
- circular-chunk-hashes
- circular-chunkhash-names
- concatenated-origin
- content-named-single-runtime
- contenthash-without-repair
- context-module
- css-chunk-import
- css-chunk-stays-analyzable
- css-content-hash-filename
- deferred-before-source-maps
- dynamic-import-contenthash
- dynamic-import-fetch-priority
- dynamic-import-public-path
- dynamic-import
- ensure-chunk-handlers
- function-chunk-filename
- glob-import
- hashed-chunk-filename
- html-chunk-stays-analyzable
- import-relative-public-path
- library-module-shipping
- library-module
- multi-chunk-import
- prefetch-child-import
- public-path-override-scope
- stand-in-lookalike
- templated-public-path
- two-depths-content-named
- html
- script-src-mixed/__snapshots__
- script-src/__snapshots__
- worker/worker-analyzable-import
- helpers
- hotCases
- esm-output/analyzable-import
- lazy-compilation/analyzable-import
- statsCases
- analyzable-esm-fallbacks
- __snapshots__
- output-module/__snapshots__
- watchCases/chunks/esm-async-chunks-hmr/0
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
83 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
87 | | - | |
| 90 | + | |
| 91 | + | |
88 | 92 | | |
89 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
90 | 99 | | |
91 | 100 | | |
92 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
93 | 107 | | |
94 | 108 | | |
95 | 109 | | |
| |||
115 | 129 | | |
116 | 130 | | |
117 | 131 | | |
118 | | - | |
119 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
120 | 136 | | |
121 | 137 | | |
122 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1215 | 1215 | | |
1216 | 1216 | | |
1217 | 1217 | | |
1218 | | - | |
| 1218 | + | |
1219 | 1219 | | |
1220 | 1220 | | |
1221 | 1221 | | |
1222 | 1222 | | |
1223 | | - | |
1224 | | - | |
1225 | | - | |
1226 | | - | |
1227 | | - | |
1228 | | - | |
1229 | | - | |
1230 | | - | |
1231 | | - | |
1232 | | - | |
1233 | | - | |
1234 | | - | |
1235 | | - | |
1236 | | - | |
1237 | | - | |
1238 | | - | |
1239 | | - | |
1240 | | - | |
1241 | | - | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
1257 | | - | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | 1223 | | |
1273 | 1224 | | |
1274 | 1225 | | |
| |||
1302 | 1253 | | |
1303 | 1254 | | |
1304 | 1255 | | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
1308 | | - | |
1309 | | - | |
1310 | | - | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
1315 | 1266 | | |
1316 | 1267 | | |
1317 | 1268 | | |
| |||
1355 | 1306 | | |
1356 | 1307 | | |
1357 | 1308 | | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
1374 | | - | |
1375 | | - | |
1376 | | - | |
1377 | | - | |
| 1309 | + | |
1378 | 1310 | | |
1379 | 1311 | | |
1380 | 1312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | 18 | | |
26 | 19 | | |
27 | 20 | | |
| |||
0 commit comments