From d3b8502d6a16fccfb1a1c383e93c90182edd0b85 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Tue, 9 Sep 2025 16:32:55 +0900 Subject: [PATCH 1/2] Fix global css hot reload issue --- .changeset/odd-doors-tan.md | 5 +++++ bindings/devup-ui-wasm/src/lib.rs | 2 +- libs/sheet/src/lib.rs | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/odd-doors-tan.md diff --git a/.changeset/odd-doors-tan.md b/.changeset/odd-doors-tan.md new file mode 100644 index 00000000..080157cb --- /dev/null +++ b/.changeset/odd-doors-tan.md @@ -0,0 +1,5 @@ +--- +"@devup-ui/wasm": patch +--- + +Fix globalCss hot reload issue diff --git a/bindings/devup-ui-wasm/src/lib.rs b/bindings/devup-ui-wasm/src/lib.rs index b6176a0f..a36e6f9a 100644 --- a/bindings/devup-ui-wasm/src/lib.rs +++ b/bindings/devup-ui-wasm/src/lib.rs @@ -49,7 +49,7 @@ impl Output { code, map, css_file, - updated_base_style, + updated_base_style: updated_base_style || default_collected, css: { if !collected && !default_collected { None diff --git a/libs/sheet/src/lib.rs b/libs/sheet/src/lib.rs index 402eb52c..900352c3 100644 --- a/libs/sheet/src/lib.rs +++ b/libs/sheet/src/lib.rs @@ -239,7 +239,7 @@ impl StyleSheet { for map in self .properties - .entry("".to_string()) + .entry(file.to_string()) .or_default() .values_mut() { @@ -259,11 +259,11 @@ impl StyleSheet { } if self .properties - .get("") + .get(file) .and_then(|v| if v.is_empty() { None } else { Some(()) }) .is_none() { - self.properties.remove(""); + self.properties.remove(file); } true } From 174fb377107bc042abd052d70a0e8697aa97bd69 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Tue, 9 Sep 2025 16:59:42 +0900 Subject: [PATCH 2/2] Fix rm global css --- bindings/devup-ui-wasm/src/lib.rs | 2 +- libs/sheet/src/lib.rs | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bindings/devup-ui-wasm/src/lib.rs b/bindings/devup-ui-wasm/src/lib.rs index a36e6f9a..e4ef4cc6 100644 --- a/bindings/devup-ui-wasm/src/lib.rs +++ b/bindings/devup-ui-wasm/src/lib.rs @@ -43,7 +43,7 @@ impl Output { import_main_css: bool, ) -> Self { let mut sheet = GLOBAL_STYLE_SHEET.lock().unwrap(); - let default_collected = sheet.rm_global_css(&filename); + let default_collected = sheet.rm_global_css(&filename, single_css); let (collected, updated_base_style) = sheet.update_styles(&styles, &filename, single_css); Self { code, diff --git a/libs/sheet/src/lib.rs b/libs/sheet/src/lib.rs index 900352c3..1100c8fc 100644 --- a/libs/sheet/src/lib.rs +++ b/libs/sheet/src/lib.rs @@ -228,7 +228,7 @@ impl StyleSheet { true } - pub fn rm_global_css(&mut self, file: &str) -> bool { + pub fn rm_global_css(&mut self, file: &str, single_css: bool) -> bool { if !self.global_css_files.contains(file) { return false; } @@ -236,10 +236,11 @@ impl StyleSheet { self.css.remove(file); self.font_faces.remove(file); + let property_key = if single_css { "" } else { file }.to_string(); for map in self .properties - .entry(file.to_string()) + .entry(property_key.clone()) .or_default() .values_mut() { @@ -259,11 +260,11 @@ impl StyleSheet { } if self .properties - .get(file) + .get(&property_key) .and_then(|v| if v.is_empty() { None } else { Some(()) }) .is_none() { - self.properties.remove(file); + self.properties.remove(&property_key); } true } @@ -934,11 +935,11 @@ mod tests { sheet.add_css("test2.tsx", "div {display:flex;}"); assert_debug_snapshot!(sheet.create_css(None, false)); - sheet.rm_global_css("test.tsx"); + sheet.rm_global_css("test.tsx", true); assert_debug_snapshot!(sheet.create_css(None, false)); - sheet.rm_global_css("wrong.tsx"); + sheet.rm_global_css("wrong.tsx", true); assert_debug_snapshot!(sheet.create_css(None, false)); } @@ -1480,7 +1481,7 @@ mod tests { None, ); - sheet.rm_global_css("test.tsx"); + sheet.rm_global_css("test.tsx", true); assert_debug_snapshot!(sheet.create_css(None, false)); let mut sheet = StyleSheet::default(); @@ -1511,7 +1512,7 @@ mod tests { assert_debug_snapshot!(sheet.create_css(None, false)); - sheet.rm_global_css("test.tsx"); + sheet.rm_global_css("test.tsx", true); assert_debug_snapshot!(sheet.create_css(None, false)); let mut sheet = StyleSheet::default(); @@ -1542,7 +1543,7 @@ mod tests { assert_debug_snapshot!(sheet.create_css(None, false)); - sheet.rm_global_css("test.tsx"); + sheet.rm_global_css("test.tsx", true); assert_debug_snapshot!(sheet.create_css(None, false)); }