Skip to content

Commit 12cb825

Browse files
docs(buildChunkGraph): explain why blocksWithNestedBlocks gates the skip (#21025)
* docs(buildChunkGraph): explain why blocksWithNestedBlocks gates the skip The previous `// TODO is this needed?` left the rationale ambiguous. Skipping a block disconnects it from its chunk group, which orphans any nested block's chunk group from this block's chunk group parent, so the check must stay. * test(chunks): cover the blocksWithNestedBlocks skip guard Pins down the case where buildChunkGraph's connectChunkGroups would otherwise skip a block whose modules are already in the entry chunk. Without the `!blocksWithNestedBlocks.has(block)` guard, the outer require.ensure's chunk group is left without a parent and gets cleaned up together with the nested chunk group, so the inner sync require fails at runtime. With the guard the test passes; removing the guard makes the test time out waiting for the inner callback.
1 parent 75f60f6 commit 12cb825

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

lib/buildChunkGraph.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,8 @@ const connectChunkGroups = (
12901290
// connections and modules can only create one version
12911291
// TODO maybe decide this per runtime
12921292
if (
1293-
// TODO is this needed?
1293+
// Blocks with nested blocks must stay connected — skipping orphans the
1294+
// nested block's chunk group from this block's chunk group parent.
12941295
!blocksWithNestedBlocks.has(block) &&
12951296
connections.every(({ chunkGroup, originChunkGroupInfo }) =>
12961297
areModulesAvailable(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 42;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// `./a` is pulled into the entry chunk by the synchronous require, so the
2+
// outer `require.ensure(["./a"], ...)` would otherwise be a candidate for the
3+
// "all dependencies already available" skip in buildChunkGraph's
4+
// `connectChunkGroups`. The `blocksWithNestedBlocks` guard prevents that skip
5+
// here — without it, the outer block's chunk group never gets a parent and
6+
// gets cleaned up together with the nested chunk group that contains `./b`,
7+
// so the inner require would fail at runtime.
8+
require("./a");
9+
10+
it("should keep nested async chunks reachable when the outer block's modules are already in the entry chunk", (done) => {
11+
require.ensure(["./a"], () => {
12+
require.ensure([], () => {
13+
const b = require("./b");
14+
expect(b).toBe(42);
15+
done();
16+
});
17+
});
18+
});

0 commit comments

Comments
 (0)