Revert "fix: Fixes boolean attributes in HTML fast-path (closes issue #405)"

This reverts commit 2ecb345a79.
This commit is contained in:
Greg Johnston 2023-01-29 16:27:28 -05:00
parent 2ecb345a79
commit 116d23f2c3
2 changed files with 10 additions and 20 deletions

View file

@ -49,9 +49,9 @@ impl Attribute {
/// Converts the attribute to its HTML value at that moment, not including /// Converts the attribute to its HTML value at that moment, not including
/// the attribute name, so it can be rendered on the server. /// the attribute name, so it can be rendered on the server.
pub fn as_nameless_value_string(&self) -> Option<String> { pub fn as_nameless_value_string(&self) -> String {
match self { match self {
Attribute::String(value) => Some(value.to_string()), Attribute::String(value) => value.to_string(),
Attribute::Fn(_, f) => { Attribute::Fn(_, f) => {
let mut value = f(); let mut value = f();
while let Attribute::Fn(_, f) = value { while let Attribute::Fn(_, f) = value {
@ -59,16 +59,11 @@ impl Attribute {
} }
value.as_nameless_value_string() value.as_nameless_value_string()
} }
Attribute::Option(_, value) => { Attribute::Option(_, value) => value
value.as_ref().map(|value| value.to_string()) .as_ref()
} .map(|value| value.to_string())
Attribute::Bool(include) => { .unwrap_or_default(),
if *include { Attribute::Bool(_) => String::new(),
Some("".to_string())
} else {
None
}
}
} }
} }
} }

View file

@ -435,13 +435,10 @@ fn attribute_to_tokens_ssr(
template.push_str(&value); template.push_str(&value);
template.push('"'); template.push('"');
} else { } else {
template.push_str("{}"); template.push_str("=\"{}\"");
let value = value.as_ref(); let value = value.as_ref();
holes.push(quote! { holes.push(quote! {
&{#value}.into_attribute(#cx) leptos::escape_attr(&{#value}.into_attribute(#cx).as_nameless_value_string()),
.as_nameless_value_string()
.map(|a| format!("{}=\"{}\"", #name, a))
.unwrap_or_default(),
}) })
} }
} }
@ -558,9 +555,7 @@ fn set_class_attribute_ssr(
template.push_str(" {}"); template.push_str(" {}");
let value = value.as_ref(); let value = value.as_ref();
holes.push(quote! { holes.push(quote! {
match &(cx, #value).into_attribute(#cx).as_nameless_value_string() leptos::escape_attr(&(cx, #value).into_attribute(#cx).as_nameless_value_string()),
.map(|a| leptos::escape_attr(&a).to_string())
.unwrap_or_default(),
}); });
} }
} }