Skip to content

Commit 644f227

Browse files
authored
fix: should recompile correctly when a shared entry specified in 'dependOn' is modified during watch mode (#11464)
1 parent 96bd3cd commit 644f227

File tree

10 files changed

+58
-3
lines changed

10 files changed

+58
-3
lines changed

crates/rspack_core/src/build_chunk_graph/incremental.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use tracing::instrument;
99

1010
use super::code_splitter::{CgiUkey, CodeSplitter, DependenciesBlockIdentifier};
1111
use crate::{
12-
AsyncDependenciesBlockIdentifier, ChunkGroupUkey, ChunkUkey, Compilation, GroupOptions,
13-
ModuleIdentifier, RuntimeSpec,
12+
AsyncDependenciesBlockIdentifier, ChunkGroupKind, ChunkGroupUkey, ChunkUkey, Compilation,
13+
GroupOptions, ModuleIdentifier, RuntimeSpec,
1414
incremental::{IncrementalPasses, Mutation},
1515
is_runtime_equal,
1616
};
@@ -249,7 +249,31 @@ impl CodeSplitter {
249249
&& chunk_group.is_initial()
250250
&& chunk_group.parents.is_empty()
251251
{
252-
return Ok(Some(vec![ChunkReCreation::Entry(name)]));
252+
edges = vec![ChunkReCreation::Entry(name)];
253+
}
254+
255+
// If the invalidated chunk group is an entrypoint, we must also invalidate any
256+
// other entrypoints that depend on it via the `dependOn` option.
257+
if matches!(chunk_group.kind, ChunkGroupKind::Entrypoint { .. }) {
258+
let dependent_entrypoints_to_invalidate: Vec<_> = compilation
259+
.entrypoints
260+
.values()
261+
.filter_map(|entrypoint_ukey| {
262+
compilation
263+
.chunk_group_by_ukey
264+
.get(entrypoint_ukey)
265+
.filter(|entrypoint| entrypoint.parents.contains(&chunk_group_ukey))
266+
.map(|_| *entrypoint_ukey)
267+
})
268+
.collect();
269+
270+
for entrypoint_ukey in dependent_entrypoints_to_invalidate {
271+
if let Some(invalidation_result) =
272+
self.invalidate_chunk_group(entrypoint_ukey, compilation)?
273+
{
274+
edges.extend(invalidation_result);
275+
}
276+
}
253277
}
254278

255279
if edges.is_empty() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./shared";

packages/rspack-test-tools/tests/watchCases/chunks/depend-on/0/foo.js

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import("./bar");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import("./bar");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should recompile correctly when a shared entry specified in 'dependOn' is modified during watch mode", (done) => {
2+
done();
3+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import("./foo")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// import("./foo")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import("@rspack/core").Configuration} */
2+
module.exports = {
3+
entry: {
4+
main: "./main.js",
5+
shared: "./shared.js",
6+
index1: {
7+
import: "./index1.js",
8+
dependOn: "shared"
9+
},
10+
index2: {
11+
import: "./index2.js",
12+
dependOn: "shared"
13+
},
14+
},
15+
output: {
16+
filename: "[name].js"
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
findBundle() {
3+
return []
4+
}
5+
};

0 commit comments

Comments
 (0)