8000 fix: should disconnect children correctly when remove available modul… · web-infra-dev/rspack@d42e8d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit d42e8d1

Browse files
authored
fix: should disconnect children correctly when remove available modules (#10503)
1 parent 35f1126 commit d42e8d1

File tree

7 files changed

+38
-1
lines changed

7 files changed

+38
-1
lines changed

crates/rspack_core/src/build_chunk_graph/available_modules.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ pub fn remove_available_modules(
220220
continue;
221221
}
222222

223+
let outgoings = chunk.outgoings_mut();
224+
for remove_id in &removed {
225+
outgoings.swap_remove(remove_id);
226+
}
227+
223228
let chunk = &chunks[chunk_index].1.chunk_desc;
224229
let outgoings = chunk.outgoings();
225230

@@ -229,7 +234,7 @@ pub fn remove_available_modules(
229234
// if all incomings from current chunk are removed, we can remove this child
230235
if child_chunk.incomings().iter().all(|incoming| {
231236
// if all incomings are not from current chunk, we disconnect them
232-
!removed.contains(incoming) && !outgoings.contains(incoming)
237+
!outgoings.contains(incoming)
233238
}) {
234239
disconnect_children.insert(*child);
235240
}

crates/rspack_core/src/build_chunk_graph/new_code_splitter.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ impl ChunkDesc {
9797
}
9898
}
9999

100+
pub(crate) fn outgoings_mut(
101+
&mut self,
102+
) -> &mut IndexSet<AsyncDependenciesBlockIdentifier, BuildHasherDefault<IdentifierHasher>> {
103+
match self {
104+
ChunkDesc::Entry(entry) => &mut entry.outgoing_blocks,
105+
ChunkDesc::Chunk(chunk) => &mut chunk.outgoing_blocks,
106+
}
107+
}
108+
100109
pub(crate) fn incomings(&self) -> &HashSet<AsyncDependenciesBlockIdentifier> {
101110
match self {
102111
ChunkDesc::Entry(entry) => &entry.incoming_blocks,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import './routes.js'
2+
3+
it('should load routes', async () => {
4+
const {value} = await import(/*webpackChunkName: "routes"*/ './module.js')
5+
6+
expect(await value).toBe(1)
7+
8+
// foo should contain no children at all
9+
const chunkId = __STATS__.namedChunkGroups.routes.chunks[0];
10+
const chunk = __STATS__.chunks.find(c => c.id === chunkId);
11+
expect(chunk.children.length).toBe(0);
12+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './routes'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = import(/*webpackChunkName: "foo"*/ './foo.js').then(({ value }) => value)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
output: {
3+
chunkFilename: "[name].js"
4+
},
5+
stats: {
6+
chunkGroups: true
7+
}
8+
};

0 commit comments

Comments
 (0)
0