Skip to content

Commit

Permalink
fix: panic in hmr cause by auxiliary_assets (#7197)
Browse files Browse the repository at this point in the history
* fix: panic in hmr cause by auxiliary_assets

* fix: prevent panic when not file in assets
  • Loading branch information
SyMind authored Jul 17, 2024
1 parent d82a8ab commit e7f5332
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions crates/rspack_core/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ fn get_asset_size(file: &str, compilation: &Compilation) -> f64 {
compilation
.assets()
.get(file)
.unwrap_or_else(|| panic!("Could not find asset by name: {file:?}"))
.get_source()
.map_or(-1f64, |s| s.size() as f64)
.and_then(|asset| asset.get_source().map(|s| s.size() as f64))
.unwrap_or(-1f64)
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -481,21 +480,24 @@ impl Stats<'_> {
.flatten()
.collect::<Vec<_>>();

let auxiliary_assets = cg
.chunks
.par_iter()
.map(|c| {
let chunk = self.compilation.chunk_by_ukey.expect_get(c);
chunk
.auxiliary_files
.par_iter()
.map(|file| StatsChunkGroupAsset {
name: file.clone(),
size: get_asset_size(file, self.compilation),
})
})
.flatten()
.collect::<Vec<_>>();
let auxiliary_assets = if chunk_group_auxiliary {
cg.chunks
.par_iter()
.map(|c| {
let chunk = self.compilation.chunk_by_ukey.expect_get(c);
chunk
.auxiliary_files
.par_iter()
.map(|file| StatsChunkGroupAsset {
name: file.clone(),
size: get_asset_size(file, self.compilation),
})
})
.flatten()
.collect::<Vec<_>>()
} else {
vec![]
};

let children = chunk_group_children.then(|| {
let ordered_children = cg.get_children_by_orders(self.compilation);
Expand Down

2 comments on commit e7f5332

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-17 58e6453) Current Change
10000_development-mode + exec 2.25 s ± 29 ms 2.27 s ± 20 ms +0.98 %
10000_development-mode_hmr + exec 700 ms ± 3.6 ms 699 ms ± 3.9 ms -0.16 %
10000_production-mode + exec 2.88 s ± 22 ms 2.86 s ± 39 ms -0.66 %
arco-pro_development-mode + exec 1.91 s ± 80 ms 1.9 s ± 90 ms -0.48 %
arco-pro_development-mode_hmr + exec 435 ms ± 3.8 ms 434 ms ± 3 ms -0.12 %
arco-pro_production-mode + exec 3.48 s ± 80 ms 3.46 s ± 61 ms -0.63 %
threejs_development-mode_10x + exec 1.77 s ± 19 ms 1.78 s ± 23 ms +0.51 %
threejs_development-mode_10x_hmr + exec 882 ms ± 8.8 ms 881 ms ± 3.7 ms -0.15 %
threejs_production-mode_10x + exec 5.78 s ± 29 ms 5.77 s ± 33 ms -0.17 %

Please sign in to comment.