From 9a2a656823bc0fbdc12eabb8cb2a57b9405d65fe Mon Sep 17 00:00:00 2001 From: schvv31n Date: Fri, 13 Oct 2023 18:50:31 +0100 Subject: [PATCH 01/20] made + + } // make sure that capitalization doesn't matter for the void children check html! { }; diff --git a/packages/yew-macro/tests/html_macro/element-fail.stderr b/packages/yew-macro/tests/html_macro/element-fail.stderr index d05a7cfad41..74f62d1aa55 100644 --- a/packages/yew-macro/tests/html_macro/element-fail.stderr +++ b/packages/yew-macro/tests/html_macro/element-fail.stderr @@ -118,28 +118,34 @@ error: the tag `` is a void element and cannot have children (hint: rewri 66 | html! { }; | ^^^^^^^^^^^^^^^^^^^ -error: the tag `` is a void element and cannot have children (hint: rewrite this as ``) +error: the tag ` } + | ^^^^^^^^^^ + +error: the tag `` is a void element and cannot have children (hint: rewrite this as ``) + --> tests/html_macro/element-fail.rs:70:13 + | +70 | html! { }; | ^^^^^^^^^^^^^^^^^^^ error: this dynamic tag is missing an expression block defining its value - --> tests/html_macro/element-fail.rs:71:14 + --> tests/html_macro/element-fail.rs:73:14 | -71 | html! { <@> }; +73 | html! { <@> }; | ^ error: this dynamic tag is missing an expression block defining its value - --> tests/html_macro/element-fail.rs:72:14 + --> tests/html_macro/element-fail.rs:74:14 | -72 | html! { <@/> }; +74 | html! { <@/> }; | ^ error: dynamic closing tags must not have a body (hint: replace it with just ``) - --> tests/html_macro/element-fail.rs:75:27 + --> tests/html_macro/element-fail.rs:77:27 | -75 | html! { <@{"test"}> }; +77 | html! { <@{"test"}> }; | ^^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { @@ -161,9 +167,9 @@ error: the property value must be either a literal or enclosed in braces. Consid }, ], } - --> tests/html_macro/element-fail.rs:83:24 + --> tests/html_macro/element-fail.rs:85:24 | -83 | html! {
}; +85 | html! {
}; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { @@ -171,9 +177,9 @@ error: the property value must be either a literal or enclosed in braces. Consid paren_token: Paren, elems: [], } - --> tests/html_macro/element-fail.rs:84:24 + --> tests/html_macro/element-fail.rs:86:24 | -84 | html! { }; +86 | html! { }; | ^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { @@ -181,9 +187,9 @@ error: the property value must be either a literal or enclosed in braces. Consid paren_token: Paren, elems: [], } - --> tests/html_macro/element-fail.rs:85:24 + --> tests/html_macro/element-fail.rs:87:24 | -85 | html! { }; +87 | html! { }; | ^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Call { @@ -197,7 +203,7 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "Some", - span: #0 bytes(2632..2636), + span: #0 bytes(2778..2782), }, arguments: PathArguments::None, }, @@ -214,9 +220,9 @@ error: the property value must be either a literal or enclosed in braces. Consid }, ], } - --> tests/html_macro/element-fail.rs:86:28 + --> tests/html_macro/element-fail.rs:88:28 | -86 | html! { }; +88 | html! { }; | ^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Path { @@ -228,16 +234,16 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "NotToString", - span: #0 bytes(2672..2683), + span: #0 bytes(2818..2829), }, arguments: PathArguments::None, }, ], }, } - --> tests/html_macro/element-fail.rs:87:27 + --> tests/html_macro/element-fail.rs:89:27 | -87 | html! { }; +89 | html! { }; | ^^^^^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Call { @@ -251,7 +257,7 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "Some", - span: #0 bytes(2711..2715), + span: #0 bytes(2857..2861), }, arguments: PathArguments::None, }, @@ -269,7 +275,7 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "NotToString", - span: #0 bytes(2716..2727), + span: #0 bytes(2862..2873), }, arguments: PathArguments::None, }, @@ -278,9 +284,9 @@ error: the property value must be either a literal or enclosed in braces. Consid }, ], } - --> tests/html_macro/element-fail.rs:88:22 + --> tests/html_macro/element-fail.rs:90:22 | -88 | html! { }; +90 | html! { }; | ^^^^^^^^^^^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Call { @@ -294,7 +300,7 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "Some", - span: #0 bytes(2755..2759), + span: #0 bytes(2901..2905), }, arguments: PathArguments::None, }, @@ -311,9 +317,9 @@ error: the property value must be either a literal or enclosed in braces. Consid }, ], } - --> tests/html_macro/element-fail.rs:89:21 + --> tests/html_macro/element-fail.rs:91:21 | -89 | html! { }; +91 | html! { }; | ^^^^^^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { @@ -321,9 +327,9 @@ error: the property value must be either a literal or enclosed in braces. Consid paren_token: Paren, elems: [], } - --> tests/html_macro/element-fail.rs:90:25 + --> tests/html_macro/element-fail.rs:92:25 | -90 | html! { }; +92 | html! { }; | ^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Tuple { @@ -331,9 +337,9 @@ error: the property value must be either a literal or enclosed in braces. Consid paren_token: Paren, elems: [], } - --> tests/html_macro/element-fail.rs:91:26 + --> tests/html_macro/element-fail.rs:93:26 | -91 | html! { }; +93 | html! { }; | ^^ error: the property value must be either a literal or enclosed in braces. Consider adding braces around your expression.: Expr::Path { @@ -345,22 +351,22 @@ error: the property value must be either a literal or enclosed in braces. Consid PathSegment { ident: Ident { ident: "NotToString", - span: #0 bytes(2862..2873), + span: #0 bytes(3008..3019), }, arguments: PathArguments::None, }, ], }, } - --> tests/html_macro/element-fail.rs:92:27 + --> tests/html_macro/element-fail.rs:94:27 | -92 | html! { }; +94 | html! { }; | ^^^^^^^^^^^ warning: use of deprecated function `compile_fail::deprecated_use_of_class`: the use of `(...)` with the attribute `class` is deprecated and will be removed in version 0.19. Use the `classes!` macro instead. - --> tests/html_macro/element-fail.rs:80:25 + --> tests/html_macro/element-fail.rs:82:25 | -80 | html! {
}; +82 | html! {
}; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(deprecated)]` on by default @@ -704,9 +710,9 @@ error[E0277]: the trait bound `(): IntoPropValue` is not satisfied = note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Cow<'static, str>: From<{integer}>` is not satisfied - --> tests/html_macro/element-fail.rs:77:15 + --> tests/html_macro/element-fail.rs:79:15 | -77 | html! { <@{55}> }; +79 | html! { <@{55}> }; | ^^^^ the trait `From<{integer}>` is not implemented for `Cow<'static, str>` | = help: the following other types implement trait `From`: From 9b8cd23b4bff214d3e133e4e03f7150299aa0e83 Mon Sep 17 00:00:00 2001 From: schvv31n Date: Fri, 13 Oct 2023 19:13:39 +0100 Subject: [PATCH 02/20] updated docs, fixed formatting --- .../yew-macro/src/html_tree/html_element.rs | 29 +++++++------ website/docs/concepts/html/elements.mdx | 41 +++++++++++++++++++ 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index 6cf90de6f7e..04c5ff8b3d7 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -53,20 +53,25 @@ impl Parse for HtmlElement { // // For dynamic tags this is done at runtime! match name.to_ascii_lowercase_string().as_str() { - "textarea" => return Err(syn::Error::new_spanned( - open.to_spanned(), - "the tag ` +``` + +Which would fail to compile, it's customary to write + +```html + +``` + +This approach takes advantage of the element property syntax described [here](./introduction.mdx). + ## Relevant examples - [Inner HTML](https://github.com/yewstack/yew/tree/master/examples/inner_html) From 8e2fd57bcc91fcf8c0940b46f5b478ce66f2ee27 Mon Sep 17 00:00:00 2001 From: schvv31n Date: Fri, 13 Oct 2023 19:20:49 +0100 Subject: [PATCH 03/20] fixed hydration test --- packages/yew/tests/hydration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yew/tests/hydration.rs b/packages/yew/tests/hydration.rs index ecaa11eb1f4..86d77e618c2 100644 --- a/packages/yew/tests/hydration.rs +++ b/packages/yew/tests/hydration.rs @@ -364,7 +364,7 @@ async fn hydration_with_suspense_not_suspended_at_start() { Ok(html! {
- + + "); } - VTagInner::Other { - ref tag, - ref children, - .. - } => { + VTagInner::Other { tag, children } => { if !VOID_ELEMENTS.contains(&tag.as_ref()) { children .render_into_stream(w, parent_scope, hydratable, tag.into()) @@ -617,6 +625,21 @@ mod ssr_tests { html! { "#); + } + + #[test] + async fn test_textarea_w_defaultvalue() { + #[function_component] + fn Comp() -> Html { + html! {
"# + r#"
"# ); gloo::utils::document() .query_selector(".take-a-break") @@ -424,7 +424,7 @@ async fn hydration_with_suspense_not_suspended_at_start() { let result = obtain_result(); assert_eq!( result.as_str(), - r#"
"# + r#"
"# ); } diff --git a/website/docs/concepts/html/elements.mdx b/website/docs/concepts/html/elements.mdx index 250a3e950d2..db6fb597324 100644 --- a/website/docs/concepts/html/elements.mdx +++ b/website/docs/concepts/html/elements.mdx @@ -176,11 +176,9 @@ Instead of writing Which would fail to compile, it's customary to write ```html - + } From 1c39a1d56d71ba91cd200e8badb368be2e0c27f6 Mon Sep 17 00:00:00 2001 From: schvv31n Date: Sun, 22 Oct 2023 19:26:48 +0100 Subject: [PATCH 11/20] fixes to error messages and formatting --- examples/suspense/src/main.rs | 2 +- packages/yew-macro/src/html_tree/html_element.rs | 6 +++--- .../yew-macro/tests/html_macro/element-fail.stderr | 2 +- packages/yew/src/dom_bundle/utils.rs | 10 +++++----- packages/yew/src/virtual_dom/vlist.rs | 2 -- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/suspense/src/main.rs b/examples/suspense/src/main.rs index a771941f4f9..8e33ea62a93 100644 --- a/examples/suspense/src/main.rs +++ b/examples/suspense/src/main.rs @@ -36,7 +36,7 @@ fn app_content() -> HtmlResult { Ok(html! {
- } diff --git a/packages/yew/src/dom_bundle/utils.rs b/packages/yew/src/dom_bundle/utils.rs index b877da9002d..6f81e6d4a68 100644 --- a/packages/yew/src/dom_bundle/utils.rs +++ b/packages/yew/src/dom_bundle/utils.rs @@ -51,6 +51,11 @@ mod feat_hydration { #[cfg(feature = "hydration")] pub(super) use feat_hydration::*; +#[cfg(test)] +// this is needed because clippy doesn't like the import not being used +#[allow(unused_imports)] +pub(super) use tests::*; + #[cfg(test)] mod tests { #![allow(dead_code)] @@ -87,8 +92,3 @@ mod tests { (root, scope, parent, sibling) } } - -#[cfg(test)] -// this is needed because clippy doesn't like the import not being used -#[allow(unused_imports)] -pub(super) use tests::*; diff --git a/packages/yew/src/virtual_dom/vlist.rs b/packages/yew/src/virtual_dom/vlist.rs index 99edb8b1157..cd9459497f1 100644 --- a/packages/yew/src/virtual_dom/vlist.rs +++ b/packages/yew/src/virtual_dom/vlist.rs @@ -202,8 +202,6 @@ mod feat_ssr { .await; } _ => { - // No idea why but clippy doesn't recognise the need for `w` to be mutable - #[allow(clippy::needless_pass_by_ref_mut)] async fn render_child_iter<'a, I>( mut children: I, w: &mut BufWriter, From 0c747e6bdf67cf132bbef84a3fcaf82908529408 Mon Sep 17 00:00:00 2001 From: schvv31n Date: Sun, 22 Oct 2023 20:08:17 +0100 Subject: [PATCH 12/20] fixed formatting --- packages/yew-macro/src/html_tree/html_element.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index d4601f0b8a8..dc822779ac6 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -56,9 +56,10 @@ impl Parse for HtmlElement { "textarea" => { return Err(syn::Error::new_spanned( open.to_spanned(), - "the tag `"#); + assert_eq!(s, r#""#); } #[test] @@ -655,6 +646,21 @@ mod ssr_tests { assert_eq!(s, r#""#); } + #[test] + async fn test_value_precedence_over_defaultvalue() { + #[function_component] + fn Comp() -> Html { + html! { "#); + } + #[test] async fn test_escaping_in_style_tag() { #[function_component] From 51c785b407725437f25e454a9d478320050aff99 Mon Sep 17 00:00:00 2001 From: schvv31n Date: Mon, 23 Oct 2023 20:13:56 +0100 Subject: [PATCH 15/20] fixed hydration test --- packages/yew/tests/hydration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yew/tests/hydration.rs b/packages/yew/tests/hydration.rs index 089c9a4fb03..84655dfa46a 100644 --- a/packages/yew/tests/hydration.rs +++ b/packages/yew/tests/hydration.rs @@ -404,7 +404,7 @@ async fn hydration_with_suspense_not_suspended_at_start() { assert_eq!( result.as_str(), - r#"
"# + r#"
"# ); gloo::utils::document() .query_selector(".take-a-break") From a0ecff571877fcb8ac074a9c67d9e943fa55f271 Mon Sep 17 00:00:00 2001 From: schvv31n Date: Mon, 23 Oct 2023 20:14:15 +0100 Subject: [PATCH 16/20] fixed hydration test --- packages/yew/tests/hydration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yew/tests/hydration.rs b/packages/yew/tests/hydration.rs index 84655dfa46a..865fcfaca58 100644 --- a/packages/yew/tests/hydration.rs +++ b/packages/yew/tests/hydration.rs @@ -404,7 +404,7 @@ async fn hydration_with_suspense_not_suspended_at_start() { assert_eq!( result.as_str(), - r#"
"# + r#"
"# ); gloo::utils::document() .query_selector(".take-a-break") From 518d49a7423b0dad6c2d05fb08a56cef726dc0e0 Mon Sep 17 00:00:00 2001 From: schvv31n Date: Mon, 23 Oct 2023 20:34:54 +0100 Subject: [PATCH 17/20] fixed hydration test --- packages/yew/tests/hydration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yew/tests/hydration.rs b/packages/yew/tests/hydration.rs index 865fcfaca58..08c56fe53bb 100644 --- a/packages/yew/tests/hydration.rs +++ b/packages/yew/tests/hydration.rs @@ -424,7 +424,7 @@ async fn hydration_with_suspense_not_suspended_at_start() { let result = obtain_result(); assert_eq!( result.as_str(), - r#"
"# + r#"
"# ); } From 66e8ad3b1c296754425c9355ec932b629724c3bb Mon Sep 17 00:00:00 2001 From: schvv31n Date: Mon, 23 Oct 2023 20:45:13 +0100 Subject: [PATCH 18/20] fixed HTML formatting --- examples/suspense/src/struct_consumer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/suspense/src/struct_consumer.rs b/examples/suspense/src/struct_consumer.rs index 12d8272bf7c..2f00888b083 100644 --- a/examples/suspense/src/struct_consumer.rs +++ b/examples/suspense/src/struct_consumer.rs @@ -59,7 +59,7 @@ impl Component for BaseAppContent { let on_take_a_break = ctx.link().callback(|_| Msg::TakeABreak); html! {
-