fix: correctly handle empty `view! {}` in hot-reloading code (closes #2421) (#2478)

This commit is contained in:
Greg Johnston 2024-04-01 16:23:29 -04:00 committed by GitHub
parent 41f3c46830
commit b79037b96f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 6 deletions

View File

@ -78,12 +78,20 @@ impl ViewMacros {
for view in visitor.views {
let span = view.span();
let id = span_to_stable_id(path, span.start().line);
let tokens = view.tokens.clone().into_iter();
// TODO handle class = ...
let rsx =
rstml::parse2(tokens.collect::<proc_macro2::TokenStream>())?;
let template = LNode::parse_view(rsx)?;
views.push(MacroInvocation { id, template });
if view.tokens.is_empty() {
views.push(MacroInvocation {
id,
template: LNode::Fragment(Vec::new()),
});
} else {
let tokens = view.tokens.clone().into_iter();
// TODO handle class = ...
let rsx = rstml::parse2(
tokens.collect::<proc_macro2::TokenStream>(),
)?;
let template = LNode::parse_view(rsx)?;
views.push(MacroInvocation { id, template });
}
}
Ok(views)
}