From 4d70da64482336fa044510c77eb194ded97b24b6 Mon Sep 17 00:00:00 2001 From: chinedufn Date: Sun, 29 Sep 2024 13:42:48 +0000 Subject: [PATCH] deploy: b3a3eec66ad5908fb067c89bcf6cafbe8a69ed9a --- 404.html | 2 +- contributing/getting-started.html | 2 +- .../html-macro/compile-time-errors.html | 2 +- contributing/html-macro/index.html | 2 +- contributing/index.html | 2 +- .../internal-design/event-handling/index.html | 2 +- contributing/internal-design/index.html | 2 +- .../internal-design/sibling-text-nodes.html | 2 +- contributing/router/index.html | 2 +- contributing/router/macro/index.html | 2 +- contributing/ways-to-contribute.html | 2 +- css-in-rust.html | 2 +- diff-patch/diff-patch-walkthrough/index.html | 22 +- .../fixing-diff-patch-issues/index.html | 2 +- diff-patch/index.html | 2 +- html-macro/boolean-attributes/index.html | 6 +- html-macro/classes/index.html | 2 +- html-macro/conditional-rendering/index.html | 2 +- html-macro/custom-components/index.html | 2 +- html-macro/html-macro.html | 2 +- html-macro/index.html | 2 +- html-macro/real-elements-and-nodes/index.html | 2 +- .../on-create-elem/index.html | 2 +- .../on-remove-elem/index.html | 2 +- html-macro/setting-inner-html/index.html | 2 +- html-macro/special-attributes/index.html | 264 ++++++++++++++++++ html-macro/text/index.html | 2 +- index.html | 2 +- introduction.html | 2 +- lists/index.html | 6 +- print.html | 50 +++- router/on-visit/index.html | 2 +- router/type-safe-url-param/index.html | 2 +- searchindex.js | 2 +- searchindex.json | 2 +- views/index.html | 2 +- views/server-side-rendering/how-to-ssr.html | 2 +- views/server-side-rendering/index.html | 2 +- views/server-side-rendering/why-ssr.html | 2 +- virtual-dom/index.html | 2 +- virtual-dom/unit-testing-views.html | 2 +- 41 files changed, 374 insertions(+), 46 deletions(-) create mode 100644 html-macro/special-attributes/index.html diff --git a/404.html b/404.html index 4467bda9..48edf573 100644 --- a/404.html +++ b/404.html @@ -97,7 +97,7 @@ diff --git a/contributing/getting-started.html b/contributing/getting-started.html index 11458e69..74845a09 100644 --- a/contributing/getting-started.html +++ b/contributing/getting-started.html @@ -95,7 +95,7 @@ diff --git a/contributing/html-macro/compile-time-errors.html b/contributing/html-macro/compile-time-errors.html index 9cf3403b..4dd58ee4 100644 --- a/contributing/html-macro/compile-time-errors.html +++ b/contributing/html-macro/compile-time-errors.html @@ -95,7 +95,7 @@ diff --git a/contributing/html-macro/index.html b/contributing/html-macro/index.html index 3b7dcf36..373929dd 100644 --- a/contributing/html-macro/index.html +++ b/contributing/html-macro/index.html @@ -95,7 +95,7 @@ diff --git a/contributing/index.html b/contributing/index.html index 89a23cf5..a133736b 100644 --- a/contributing/index.html +++ b/contributing/index.html @@ -95,7 +95,7 @@ diff --git a/contributing/internal-design/event-handling/index.html b/contributing/internal-design/event-handling/index.html index 93925982..32a155b9 100644 --- a/contributing/internal-design/event-handling/index.html +++ b/contributing/internal-design/event-handling/index.html @@ -95,7 +95,7 @@ diff --git a/contributing/internal-design/index.html b/contributing/internal-design/index.html index 8a7e4cb3..a948e63e 100644 --- a/contributing/internal-design/index.html +++ b/contributing/internal-design/index.html @@ -95,7 +95,7 @@ diff --git a/contributing/internal-design/sibling-text-nodes.html b/contributing/internal-design/sibling-text-nodes.html index d47dbbd0..427bd7f7 100644 --- a/contributing/internal-design/sibling-text-nodes.html +++ b/contributing/internal-design/sibling-text-nodes.html @@ -95,7 +95,7 @@ diff --git a/contributing/router/index.html b/contributing/router/index.html index 8c471611..900b2cf8 100644 --- a/contributing/router/index.html +++ b/contributing/router/index.html @@ -95,7 +95,7 @@ diff --git a/contributing/router/macro/index.html b/contributing/router/macro/index.html index f25365ea..137ad53a 100644 --- a/contributing/router/macro/index.html +++ b/contributing/router/macro/index.html @@ -95,7 +95,7 @@ diff --git a/contributing/ways-to-contribute.html b/contributing/ways-to-contribute.html index f9664d2e..f37feada 100644 --- a/contributing/ways-to-contribute.html +++ b/contributing/ways-to-contribute.html @@ -95,7 +95,7 @@ diff --git a/css-in-rust.html b/css-in-rust.html index 74bcee84..b559af73 100644 --- a/css-in-rust.html +++ b/css-in-rust.html @@ -95,7 +95,7 @@ diff --git a/diff-patch/diff-patch-walkthrough/index.html b/diff-patch/diff-patch-walkthrough/index.html index 73cc7067..3163c408 100644 --- a/diff-patch/diff-patch-walkthrough/index.html +++ b/diff-patch/diff-patch-walkthrough/index.html @@ -95,7 +95,7 @@ @@ -499,7 +499,13 @@

Patching

} } AttributeValue::Bool(val_bool) => { - if *val_bool { + // Use `set_checked` instead of `{set,remove}_attribute` for the `checked` attribute. + // The "checked" attribute only determines default checkedness, + // but `percy-dom` takes `checked` to specify the actual checkedness. + // See crates/percy-dom/tests/checked_attribute.rs for more info. + if *attrib_name == "checked" { + maybe_set_checked_property(node, *val_bool); + } else if *val_bool { node.set_attribute(attrib_name, "")?; } else { node.remove_attribute(attrib_name)?; @@ -648,6 +654,11 @@

Patching

Ok(()) } + Patch::CheckedAttributeUnchanged(_node_idx, value) => { + maybe_set_checked_property(node, value.as_bool().unwrap()); + + Ok(()) + } Patch::SpecialAttribute(special) => match special { PatchSpecialAttribute::CallOnCreateElemOnExistingNode(_node_idx, new_node) => { new_node @@ -770,6 +781,13 @@

Patching

} } +// See crates/percy-dom/tests/checked_attribute.rs +fn maybe_set_checked_property(node: &Element, checked: bool) { + if let Some(input_node) = node.dyn_ref::<HtmlInputElement>() { + input_node.set_checked(checked); + } +} + // Looks for a property on the element. If it's there then this is a Percy element. // // TODO: We need to know not just if the node was created by Percy... but if it was created by diff --git a/diff-patch/fixing-diff-patch-issues/index.html b/diff-patch/fixing-diff-patch-issues/index.html index 686faa1a..a2b5a85f 100644 --- a/diff-patch/fixing-diff-patch-issues/index.html +++ b/diff-patch/fixing-diff-patch-issues/index.html @@ -95,7 +95,7 @@ diff --git a/diff-patch/index.html b/diff-patch/index.html index 69451f85..f156307b 100644 --- a/diff-patch/index.html +++ b/diff-patch/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/boolean-attributes/index.html b/html-macro/boolean-attributes/index.html index 087a3bf1..9e5af717 100644 --- a/html-macro/boolean-attributes/index.html +++ b/html-macro/boolean-attributes/index.html @@ -95,7 +95,7 @@ @@ -196,7 +196,7 @@

Boolean - @@ -214,7 +214,7 @@

Boolean - diff --git a/html-macro/classes/index.html b/html-macro/classes/index.html index 3119cd05..d8172237 100644 --- a/html-macro/classes/index.html +++ b/html-macro/classes/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/conditional-rendering/index.html b/html-macro/conditional-rendering/index.html index 5ecaaed6..da5699af 100644 --- a/html-macro/conditional-rendering/index.html +++ b/html-macro/conditional-rendering/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/custom-components/index.html b/html-macro/custom-components/index.html index 56e2fe73..9f7afdef 100644 --- a/html-macro/custom-components/index.html +++ b/html-macro/custom-components/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/html-macro.html b/html-macro/html-macro.html index 26ff85c2..cdd88a26 100644 --- a/html-macro/html-macro.html +++ b/html-macro/html-macro.html @@ -95,7 +95,7 @@ diff --git a/html-macro/index.html b/html-macro/index.html index 9cc752ea..984daec8 100644 --- a/html-macro/index.html +++ b/html-macro/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/real-elements-and-nodes/index.html b/html-macro/real-elements-and-nodes/index.html index 36ee2943..d6f8d411 100644 --- a/html-macro/real-elements-and-nodes/index.html +++ b/html-macro/real-elements-and-nodes/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/real-elements-and-nodes/on-create-elem/index.html b/html-macro/real-elements-and-nodes/on-create-elem/index.html index fed8bac6..b770ee98 100644 --- a/html-macro/real-elements-and-nodes/on-create-elem/index.html +++ b/html-macro/real-elements-and-nodes/on-create-elem/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/real-elements-and-nodes/on-remove-elem/index.html b/html-macro/real-elements-and-nodes/on-remove-elem/index.html index 12e77f0a..b2cb194b 100644 --- a/html-macro/real-elements-and-nodes/on-remove-elem/index.html +++ b/html-macro/real-elements-and-nodes/on-remove-elem/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/setting-inner-html/index.html b/html-macro/setting-inner-html/index.html index f45619a9..19bcab2a 100644 --- a/html-macro/setting-inner-html/index.html +++ b/html-macro/setting-inner-html/index.html @@ -95,7 +95,7 @@ diff --git a/html-macro/special-attributes/index.html b/html-macro/special-attributes/index.html new file mode 100644 index 00000000..9d712bce --- /dev/null +++ b/html-macro/special-attributes/index.html @@ -0,0 +1,264 @@ + + + + + + Special Attributes - Percy - Isomorphic Web Apps in Rust + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+

Special Virtual DOM Attributes

+

Some virtual DOM attributes do not merely set or remove the corresponding HTML attribute of the same name.

+

checked

+

According to the HTML spec, the checked HTML attribute only controls the default checkedness. +Changing the checked HTML attribute may not cause the checkbox's checkedness to change.

+

By contrast: specifying html! { <input checked={bool} /> } causes percy to always render the checkbox with the specified checkedness.

+
    +
  • If the VDOM is updated from html! { <input checked=true /> } to html { <input checked=false /> }, the input element's checkedness will definitely change.
  • +
  • If the VDOM is updated from html! { <input checked=true /> } to html { <input checked=true /> }, the input element's checkedness will be reverted to true even if the user interacted with the checkbox in between.
  • +
+

percy-dom updates the checked property (current checkedness, not reflected in HTML).

+

This behavior is more desirable because percy developers are accustomed to declaratively controlling the DOM and rendered HTML.

+

percy-dom does not affect the presence of the checked attribute (default checkedness, reflected in HTML).

+

This means that if you need to configure the checked attribute (this should almost never be the case if your GUI state is driven by the backend state) then percy-dom won't get in your way.

+

value

+

According to the HTML spec, the value HTML attribute only controls the default value. +Changing the value HTML attribute may not cause the input element's value to change.

+

By contrast: specifying html! { <input value="..." /> } causes percy to always render the input element with the specified value.

+
    +
  • If the VDOM is updated from html! { <input value="hello" /> } to html { <input value="goodbye" /> }, the input element's value will definitely change.
  • +
  • If the VDOM is updated from html! { <input value="hello" /> } to html { <input value="hello" /> }, the input element's value will be reverted to "hello" even if the user interacted with the input element in between.
  • +
+

percy updates both

+
    +
  • the value attribute (default value, reflected in HTML) and,
  • +
  • the value property (current value, not reflected in HTML).
  • +
+

Setting the value property is desirable because percy developers are accustomed to declaratively controlling the DOM and rendered HTML.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/html-macro/text/index.html b/html-macro/text/index.html index a9bc49aa..ca20fc16 100644 --- a/html-macro/text/index.html +++ b/html-macro/text/index.html @@ -95,7 +95,7 @@ diff --git a/index.html b/index.html index 02ce3b38..624d025a 100644 --- a/index.html +++ b/index.html @@ -95,7 +95,7 @@ diff --git a/introduction.html b/introduction.html index 251d56ae..a24c5ead 100644 --- a/introduction.html +++ b/introduction.html @@ -95,7 +95,7 @@ diff --git a/lists/index.html b/lists/index.html index b6138e37..4016e3f1 100644 --- a/lists/index.html +++ b/lists/index.html @@ -95,7 +95,7 @@ @@ -201,7 +201,7 @@

Keys