Skip to content

Commit 59ca3b1

Browse files
committed
fix(rspack_core): correct COW uniqueness check in dependency_by_id_mut to consider weak refs and improve panic message
1 parent 11e0acb commit 59ca3b1

File tree

1 file changed

+5
-2
lines changed
  • crates/rspack_core/src/module_graph

1 file changed

+5
-2
lines changed

crates/rspack_core/src/module_graph/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,13 @@ impl ModuleGraph {
598598
.dependencies
599599
.get_mut(dependency_id)
600600
.unwrap_or_else(|| panic!("Dependency with ID {dependency_id:?} not found"));
601-
if Arc::strong_count(dep) != 1 {
601+
// Ensure unique mutable access; account for both strong and weak refs.
602+
if Arc::get_mut(dep).is_none() {
602603
*dep = Arc::from(clone_box(dep.as_ref()));
603604
}
604-
Arc::get_mut(dep).unwrap_or_else(|| panic!("Dependency with ID {dependency_id:?} not found"))
605+
Arc::get_mut(dep).unwrap_or_else(|| {
606+
panic!("Cannot obtain unique mutable access for dependency with ID {dependency_id:?}")
607+
})
605608
}
606609

607610
/// Uniquely identify a module by its dependency

0 commit comments

Comments
 (0)