Skip to content

Commit 3618e21

Browse files
committed
fix: keep sibling entry connections when re-factorizing a shared entry module
The null-origin seed cleanup is meant for freshly minted seeding dependencies (prefetch chains); a re-factorize reuses a persisted entry dependency, so the cleanup dropped other entries pointing at the same module.
1 parent a8c4681 commit 3618e21

7 files changed

Lines changed: 55 additions & 4 deletions

File tree

‎lib/Compilation.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
25102510
* @property {boolean=} recursive recurse into dependencies of the created module
25112511
* @property {boolean=} connectOrigin connect the resolved module with the origin module
25122512
* @property {boolean=} checkCycle check the cycle dependencies of the created module
2513+
* @property {boolean=} reusedDependencies dependencies are persisted from the previous compilation (incremental re-factorize), not freshly minted seeds
25132514
*/
25142515

25152516
/**
@@ -2527,7 +2528,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
25272528
context,
25282529
recursive = true,
25292530
connectOrigin = recursive,
2530-
checkCycle = !recursive
2531+
checkCycle = !recursive,
2532+
reusedDependencies = false
25312533
},
25322534
callback
25332535
) {
@@ -2643,8 +2645,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
26432645
moduleGraph.setIssuer(module, null);
26442646
this._incrementalSeedRoots.add(module);
26452647
// a fresh seeding dependency is minted each make (prefetch chains) —
2646-
// drop the previous makes' connections or they accumulate unbounded
2647-
if (dependencies.length > 0) {
2648+
// drop the previous makes' connections or they accumulate unbounded;
2649+
// a re-factorize reuses a persisted dependency, where this would
2650+
// drop sibling entries pointing at the same module
2651+
if (dependencies.length > 0 && !reusedDependencies) {
26482652
moduleGraph._removeStaleSeedConnections(module, dependencies);
26492653
}
26502654
} else {
@@ -3478,7 +3482,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
34783482
originModule,
34793483
context:
34803484
(originModule ? originModule.context : module.context) || undefined,
3481-
connectOrigin: originModule !== null
3485+
connectOrigin: originModule !== null,
3486+
reusedDependencies: true
34823487
},
34833488
(err, newModule) => {
34843489
const built = newModule || module;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
it("should keep every entry of a changed shared module connected", () => {
2+
const fs = __non_webpack_require__("fs");
3+
const path = __non_webpack_require__("path");
4+
const expected = `__sharedValue = ${WATCH_STEP === "0" ? 1 : 2}`;
5+
for (const name of ["second.js", "third.js"]) {
6+
const content = fs.readFileSync(path.resolve(__dirname, name), "utf8");
7+
expect(content).toContain(expected);
8+
}
9+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global.__sharedValue = 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global.__sharedValue = 2;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
/**
4+
* @param {string} source source
5+
* @returns {string} source
6+
*/
7+
module.exports = (source) => source;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
module.exports = {
4+
findBundle: () => "./bundle.js"
5+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
const path = require("path");
4+
5+
/** @type {import("../../../../").Configuration} */
6+
module.exports = {
7+
entry: {
8+
bundle: "./index.js",
9+
second: "./shared.js",
10+
third: "./shared.js"
11+
},
12+
output: {
13+
filename: "[name].js"
14+
},
15+
module: {
16+
rules: [
17+
{
18+
test: /shared\.js$/,
19+
use: path.resolve(__dirname, "loader.js")
20+
}
21+
]
22+
}
23+
};

0 commit comments

Comments
 (0)