diff --git a/.gitignore b/.gitignore index 8dc8bbd379e..ff4c7afbdf4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,3 @@ target/ *.iml /.idea/ /.vscode/ - -# artifacts from npm -node_modules/ -package.json -package-lock.json diff --git a/packages/yew/src/virtual_dom/vtag.rs b/packages/yew/src/virtual_dom/vtag.rs index f056a329581..51caaa3de92 100644 --- a/packages/yew/src/virtual_dom/vtag.rs +++ b/packages/yew/src/virtual_dom/vtag.rs @@ -92,9 +92,6 @@ impl InputFields { } } -// Clippy doesn't recognise that `defaultvalue` is read in other files and in this very file when -// the "ssr" feature is enabled. -#[allow(unused)] #[derive(Debug, Clone, Default)] pub(crate) struct TextareaFields { /// Contains the value of an @@ -102,6 +99,7 @@ pub(crate) struct TextareaFields { pub(crate) value: Value, /// Contains the default value of /// [TextAreaElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea). + #[allow(unused)] // unused only if both "csr" and "ssr" features are off pub(crate) defaultvalue: Option, } @@ -492,26 +490,16 @@ mod feat_ssr { } }; - match &self.inner { - VTagInner::Input(InputFields { value, checked }) => { - if let Some(value) = value.as_deref() { - write_attr(w, "value", Some(value)); - } - - // Setting is as an attribute sets the `defaultChecked` property. Only emit this - // if it's explicitly set to checked. - if *checked == Some(true) { - write_attr(w, "checked", None); - } + if let VTagInner::Input(InputFields { value, checked }) = &self.inner { + if let Some(value) = value.as_deref() { + write_attr(w, "value", Some(value)); } - VTagInner::Textarea(TextareaFields { value, .. }) => { - if let Some(value) = value.as_deref() { - write_attr(w, "value", Some(value)); - } + // Setting is as an attribute sets the `defaultChecked` property. Only emit this + // if it's explicitly set to checked. + if *checked == Some(true) { + write_attr(w, "checked", None); } - - _ => (), } for (k, v) in self.attributes.iter() { @@ -522,8 +510,11 @@ mod feat_ssr { match &self.inner { VTagInner::Input(_) => {} - VTagInner::Textarea(TextareaFields { defaultvalue, .. }) => { - if let Some(def) = defaultvalue { + VTagInner::Textarea(TextareaFields { + value, + defaultvalue, + }) => { + if let Some(def) = value.as_ref().or(defaultvalue.as_ref()) { VText::new(def.clone()) .render_into_stream(w, parent_scope, hydratable, VTagKind::Other) .await; @@ -637,7 +628,7 @@ mod ssr_tests { .render() .await; - assert_eq!(s, r#""#); + 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]