Skip to content

Commit

Permalink
fix: correctly mount/unmount hydrated static text nodes in nightly mo…
Browse files Browse the repository at this point in the history
…de (closes #3334) (#3336)
  • Loading branch information
gbj authored Dec 8, 2024
1 parent 2aa9827 commit 775bea4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tachys/src/view/static_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -180,8 +180,11 @@ impl<const V: &'static str> RenderHtml for Static<V> {
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);
}
Expand All @@ -198,13 +201,18 @@ impl<const V: &'static str> RenderHtml for Static<V> {
} 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)
}
}

Expand Down

0 comments on commit 775bea4

Please sign in to comment.