Merge pull request #301 from leptos-rs/ssr-inner-html

Fix SSR of elements with `inner_html`
This commit is contained in:
Greg Johnston 2023-01-11 21:59:45 -05:00 committed by GitHub
commit 7eaa36812d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -382,24 +382,33 @@ impl View {
} else {
let tag_name = el.name;
let mut inner_html = None;
let attrs = el
.attrs
.into_iter()
.map(|(name, value)| -> Cow<'static, str> {
.filter_map(|(name, value)| -> Option<Cow<'static, str>> {
if value.is_empty() {
format!(" {name}").into()
Some(format!(" {name}").into())
} else if name == "inner_html" {
inner_html = Some(value);
None
} else {
format!(
" {name}=\"{}\"",
html_escape::encode_double_quoted_attribute(&value)
Some(
format!(
" {name}=\"{}\"",
html_escape::encode_double_quoted_attribute(&value)
)
.into(),
)
.into()
}
})
.join("");
if el.is_void {
format!("<{tag_name}{attrs}/>").into()
} else if let Some(inner_html) = inner_html {
format!("<{tag_name}{attrs}>{inner_html}</{tag_name}>").into()
} else {
let children = el
.children