Преглед изворни кода

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
Evan Almloff пре 1 година
родитељ
комит
6a781af693
3 измењених фајлова са 15 додато и 1 уклоњено
  1. 1 0
      .gitignore
  2. 9 0
      packages/ssr/src/cache.rs
  3. 5 1
      packages/web/src/rehydrate.rs

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
+.dioxus
 /target
 /packages/playwright-tests/web/dist
 /packages/playwright-tests/fullstack/dist

+ 9 - 0
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, "<!--node-id")?;
+                    chain.segments.push(Segment::RootNodeMarker);
+                    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))

+ 5 - 1
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(())
     }