Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should recalculate order indices in outdated entrypoint #8970

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 41 additions & 17 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,32 +813,56 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
chunk_group.next_pre_order_index = 0;
chunk_group.next_post_order_index = 0;

let chunk_group = compilation
.chunk_group_by_ukey
.expect_get(&chunk_group_ukey);

let module_graph = compilation.get_module_graph();
let Some(blocks) = self.blocks_by_cgi.get(&cgi.ukey) else {
continue;
};

let mut blocks = blocks.iter().copied().collect::<Vec<_>>();
blocks.sort_unstable();
let Some(DependenciesBlockIdentifier::AsyncDependenciesBlock(block)) =
blocks.first().copied()
else {
continue;
let roots = if let Some(blocks) = self.blocks_by_cgi.get(&cgi.ukey) {
let mut blocks = blocks.iter().copied().collect::<Vec<_>>();
blocks.sort_unstable();

// if one chunk group has multiple blocks, the modules order indices are very likely incorrect
// in every block. For example:
// one chunk import 'a' first then import 'b', while in other chunk import 'b' first then import 'a'.
// User use webpackChunkName to merge these 2 chunks, the `a` and `b` will be in the same chunk, their
// orders cannot be determined.
// Only use the first block to calculate the order indices.
let Some(DependenciesBlockIdentifier::AsyncDependenciesBlock(block)) =
blocks.first().copied()
else {
continue;
};

let Some(block) = module_graph.block_by_id(&block) else {
continue;
};
let root_modules = block
.get_dependencies()
.iter()
.filter_map(|dep| module_graph.module_identifier_by_dependency_id(dep))
.copied()
.collect::<Vec<_>>();

Some(root_modules)
} else if chunk_group.kind.is_entrypoint() && chunk_group.is_initial() {
let entry_chunk_ukey = chunk_group.get_entry_point_chunk();
let entry_modules = compilation
.chunk_graph
.get_chunk_entry_modules(&entry_chunk_ukey);
Some(entry_modules)
} else {
None
};

let Some(block) = module_graph.block_by_id(&block) else {
let Some(roots) = roots else {
continue;
};
let blocks = block
.get_dependencies()
.iter()
.filter_map(|dep| module_graph.module_identifier_by_dependency_id(dep))
.copied()
.collect::<Vec<_>>();

let mut visited = IdentifierIndexSet::default();

for root in blocks {
for root in roots {
let mut ctx = (0, 0, Default::default());
self.calculate_order_index(root, &runtime, &mut visited, &mut ctx, compilation);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.styleB {
background: blue;
}

.styleA {
background: red;
}

.styleB {
background: blue;
}
Loading