From c944359681e2b0383d6ec8029e27564840ecff67 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Sat, 7 Dec 2024 16:56:40 -0500 Subject: [PATCH] fix: correctly mount/unmount hydrated static text nodes in nightly mode (closes #3334) --- tachys/src/view/static_types.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tachys/src/view/static_types.rs b/tachys/src/view/static_types.rs index 6f455c7f32..ad02048fdb 100644 --- a/tachys/src/view/static_types.rs +++ b/tachys/src/view/static_types.rs @@ -5,7 +5,7 @@ use super::{ use crate::{ html::attribute::{Attribute, AttributeKey, AttributeValue, NextAttribute}, hydration::Cursor, - renderer::Rndr, + renderer::{CastFrom, Rndr}, }; use std::marker::PhantomData; @@ -180,8 +180,11 @@ impl RenderHtml for Static { if matches!(position, Position::NextChildAfterText) { buf.push_str("") } - if escape { - buf.push_str(&html_escape::encode_text(V)); + if V.is_empty() && escape { + buf.push(' '); + } else if escape { + let escaped = html_escape::encode_text(V); + buf.push_str(&escaped); } else { buf.push_str(V); } @@ -198,13 +201,18 @@ impl RenderHtml for Static { } else { cursor.sibling(); } + + // separating placeholder marker comes before text node if matches!(position.get(), Position::NextChildAfterText) { cursor.sibling(); } - position.set(Position::NextChildAfterText); - // no view state is created when hydrating, because this is static - None + let node = cursor.current(); + let node = crate::renderer::types::Text::cast_from(node.clone()) + .unwrap_or_else(|| { + crate::hydration::failed_to_cast_text_node(node) + }); + Some(node) } }