Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly mount/unmount hydrated static text nodes in nightly mode (closes #3334) #3336

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading