Skip to content

Commit

Permalink
fix: chunkLoading false (#4167)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Sep 11, 2023
1 parent 509abcf commit 94f0422
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
9 changes: 3 additions & 6 deletions crates/rspack_core/src/chunk_graph/chunk_graph_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,11 @@ impl ChunkGraph {
&self,
block: &ModuleIdentifier,
chunk_group_by_ukey: &'a ChunkGroupByUkey,
) -> &'a ChunkGroup {
let ukey = self
) -> Option<&'a ChunkGroup> {
self
.block_to_chunk_group_ukey
.get(block)
.unwrap_or_else(|| panic!("Block({block:?}) doesn't have corresponding ChunkGroup"));
chunk_group_by_ukey
.get(ukey)
.unwrap_or_else(|| panic!("ChunkGroup({ukey:?}) doesn't exist"))
.and_then(|ukey| chunk_group_by_ukey.get(ukey))
}

pub fn connect_block_and_chunk_group(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl DependencyTemplate for WorkerDependency {
let chunk_id = compilation
.module_graph
.module_identifier_by_dependency_id(&self.id)
.map(|module| {
.and_then(|module| {
compilation
.chunk_graph
.get_block_chunk_group(module, &compilation.chunk_group_by_ukey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ impl RuntimeModule for LoadChunkWithModuleRuntimeModule {
let map = async_modules
.par_iter()
.filter_map(|identifier| {
let mut chunk_ids = {
let chunk_group = compilation
.chunk_graph
.get_block_chunk_group(identifier, &compilation.chunk_group_by_ukey);
chunk_group
if let Some(chunk_group) = compilation
.chunk_graph
.get_block_chunk_group(identifier, &compilation.chunk_group_by_ukey)
{
let mut chunk_ids = chunk_group
.chunks
.iter()
.filter_map(|chunk_ukey| {
Expand All @@ -68,21 +68,22 @@ impl RuntimeModule for LoadChunkWithModuleRuntimeModule {
None
}
})
.collect::<Vec<_>>()
};
if chunk_ids.is_empty() {
return None;
}
chunk_ids.sort_unstable();
let module = compilation
.module_graph
.module_graph_module_by_identifier(identifier)
.expect("no module found");
.collect::<Vec<_>>();
if chunk_ids.is_empty() {
return None;
}
chunk_ids.sort_unstable();
let module = compilation
.module_graph
.module_graph_module_by_identifier(identifier)
.expect("no module found");

let module_id = module.id(&compilation.chunk_graph);
let module_id_expr = serde_json::to_string(module_id).expect("invalid module_id");
let module_id = module.id(&compilation.chunk_graph);
let module_id_expr = serde_json::to_string(module_id).expect("invalid module_id");

Some((module_id_expr, chunk_ids))
return Some((module_id_expr, chunk_ids));
}
None
})
.collect::<HashMap<String, Vec<String>>>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
it("should work with chunk loading false", function () {
import("./dynamic").then(module => {
expect(module.value).toBe(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
output: {
chunkLoading: false
}
};

0 comments on commit 94f0422

Please sign in to comment.