From 5587ccd1eba641d89864b36e6588bcfa67b96d83 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Sat, 14 Jun 2025 15:47:48 -0400 Subject: [PATCH] fix: don't render a comment node for `()` attributes in `template` (closes #4079) (#4080) --- tachys/src/html/element/mod.rs | 2 +- tachys/src/view/mod.rs | 11 +++++++++++ tachys/src/view/tuples.rs | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tachys/src/html/element/mod.rs b/tachys/src/html/element/mod.rs index dea8a6a51..3b5858bdb 100644 --- a/tachys/src/html/element/mod.rs +++ b/tachys/src/html/element/mod.rs @@ -709,7 +709,7 @@ where buf.push('<'); buf.push_str(E::TAG); - ::to_template( + ::to_template_attribute( buf, &mut class, &mut style, diff --git a/tachys/src/view/mod.rs b/tachys/src/view/mod.rs index 89d910526..479810514 100644 --- a/tachys/src/view/mod.rs +++ b/tachys/src/view/mod.rs @@ -437,6 +437,17 @@ pub trait ToTemplate { inner_html: &mut String, position: &mut Position, ); + + /// Renders a view type to a template in attribute position. + fn to_template_attribute( + buf: &mut String, + class: &mut String, + style: &mut String, + inner_html: &mut String, + position: &mut Position, + ) { + Self::to_template(buf, class, style, inner_html, position); + } } /// Keeps track of what position the item currently being hydrated is in, relative to its siblings diff --git a/tachys/src/view/tuples.rs b/tachys/src/view/tuples.rs index 220fc92fb..2513d086a 100644 --- a/tachys/src/view/tuples.rs +++ b/tachys/src/view/tuples.rs @@ -103,6 +103,15 @@ impl ToTemplate for () { ) { buf.push_str(""); } + + fn to_template_attribute( + _buf: &mut String, + _class: &mut String, + _style: &mut String, + _inner_html: &mut String, + _position: &mut Position, + ) { + } } impl Render for (A,) {