Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/odd-doors-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Fix globalCss hot reload issue
4 changes: 2 additions & 2 deletions bindings/devup-ui-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ 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,
map,
css_file,
updated_base_style,
updated_base_style: updated_base_style || default_collected,
css: {
if !collected && !default_collected {
None
Expand Down
19 changes: 10 additions & 9 deletions libs/sheet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,19 @@ 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;
}
self.global_css_files.remove(file);
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("".to_string())
.entry(property_key.clone())
.or_default()
.values_mut()
{
Expand All @@ -259,11 +260,11 @@ impl StyleSheet {
}
if self
.properties
.get("")
.get(&property_key)
.and_then(|v| if v.is_empty() { None } else { Some(()) })
.is_none()
{
self.properties.remove("");
self.properties.remove(&property_key);
}
true
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}

Expand Down