feat: bool attr white list

This commit is contained in:
YuKun Liu 2022-01-09 02:02:23 +08:00
parent 4f1894ff5c
commit 8f4aa84f1a
3 changed files with 67 additions and 2 deletions

View file

@ -18,6 +18,11 @@ fn app(cx: Scope) -> Element {
disabled: "{disabled}", disabled: "{disabled}",
"lower button" "lower button"
} }
input {
value: "false",
}
} }
}) })
} }

View file

@ -369,8 +369,38 @@ class Interpreter {
node.innerHTML = value; node.innerHTML = value;
break; break;
default: default:
const bool_attrs = [
"allowfullscreen",
"allowpaymentrequest",
"async",
"autofocus",
"autoplay",
"checked",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
]
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364 // https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
if (value == "false" && name != "capture" && name != "download") { if (value == "false" && bool_attrs.indexOf(name)) {
node.removeAttribute(name); node.removeAttribute(name);
} else { } else {
node.setAttribute(name, value); node.setAttribute(name, value);

View file

@ -348,8 +348,38 @@ impl WebsysDom {
} }
} }
_ => { _ => {
let bool_attrs = vec![
"allowfullscreen",
"allowpaymentrequest",
"async",
"autofocus",
"autoplay",
"checked",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
];
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364 // https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
if value == "false" && ((name != "capture") && (name != "download")) { if value == "false" && bool_attrs.contains(&name) {
if let Some(el) = node.dyn_ref::<Element>() { if let Some(el) = node.dyn_ref::<Element>() {
let _ = el.remove_attribute(name); let _ = el.remove_attribute(name);
} }