Fix hot reload diffing to empty rsx (#3567)

* Fix hot reloading to empty rsx

* Only normalize the template when hot reloading and rendering

* add a test for emptying out an rsx block in hot reloading
This commit is contained in:
Evan Almloff authored and GitHub committed 2025-01-21 00:33:29 -08:00
1 parent 2c6a5212fc
commit f99e50b0aa
3 files changed
+61 -26

No files matched your search

+5 -2
View File
@@ -122,7 +122,10 @@ impl HotReloadResult {
new: &TemplateBody,
name: String,
) -> Option<Self> {
let full_rebuild_state = LastBuildState::new(full_rebuild_state, name);
// Normalize both the full rebuild state and the new state for rendering
let full_rebuild_state = full_rebuild_state.normalized();
let new = new.normalized();
let full_rebuild_state = LastBuildState::new(&full_rebuild_state, name);
let mut s = Self {
full_rebuild_state,
templates: Default::default(),
@@ -131,7 +134,7 @@ impl HotReloadResult {
literal_component_properties: Default::default(),
};
s.hotreload_body::<Ctx>(new)?;
s.hotreload_body::<Ctx>(&new)?;
Some(s)
}
@@ -467,6 +467,32 @@ fn invalid_cases() {
assert!(added.is_none());
}
#[test]
fn invalid_empty_rsx() {
let old_template = quote! {
div {
for item in vec![1, 2, 3, 4] {
div { "asasddasdasd" }
div { "123" }
}
for item in vec![4, 5, 6] {
span { "asasddasdasd" }
span { "123" }
}
}
};
// empty out the whole rsx block
let new_template = quote! {};
let location = "file:line:col:0";
let old_template: CallBody = syn::parse2(old_template).unwrap();
let new_template: CallBody = syn::parse2(new_template).unwrap();
assert!(hotreload_callbody::<Mock>(&old_template, &new_template).is_none());
}
#[test]
fn attributes_reload() {
let old = quote! {