From 6a781af6933202ca4dd241f41a16f6d240551c86 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 29 Mar 2024 20:22:55 -0500 Subject: [PATCH] Fix hydration for static text nodes at the root of the template (#2184) * Fix hydration for static text nodes at the root of the template * fix clippy --- .gitignore | 1 + packages/ssr/src/cache.rs | 9 +++++++++ packages/web/src/rehydrate.rs | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9f61ad64e..f7156b125 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.dioxus /target /packages/playwright-tests/web/dist /packages/playwright-tests/fullstack/dist diff --git a/packages/ssr/src/cache.rs b/packages/ssr/src/cache.rs index c2962d11b..dd2d316aa 100644 --- a/packages/ssr/src/cache.rs +++ b/packages/ssr/src/cache.rs @@ -156,11 +156,20 @@ impl StringCache { cur_path.pop(); } TemplateNode::Text { text } => { + // write the id if we are prerendering and this is a root node that may need to be removed in the future + if prerender && is_root { + write!(chain, "")?; + } write!( chain, "{}", askama_escape::escape(text, askama_escape::Html) )?; + if prerender && is_root { + write!(chain, "")?; + } } TemplateNode::Dynamic { id: idx } | TemplateNode::DynamicText { id: idx } => { chain.segments.push(Segment::Node(*idx)) diff --git a/packages/web/src/rehydrate.rs b/packages/web/src/rehydrate.rs index 9e16ff77c..5c425de79 100644 --- a/packages/web/src/rehydrate.rs +++ b/packages/web/src/rehydrate.rs @@ -113,7 +113,11 @@ impl WebsysDom { ids, to_mount, )?, - _ => {} + TemplateNode::Text { .. } => { + if let Some(id) = root_id { + ids.push(id.0 as u32); + } + } } Ok(()) }