Browse Source

always load the templates in hydration

Evan Almloff 2 years ago
parent
commit
9baef6bcd9
2 changed files with 3 additions and 3 deletions
  1. 1 1
      packages/core/src/mutations.rs
  2. 2 2
      packages/web/src/lib.rs

+ 1 - 1
packages/core/src/mutations.rs

@@ -26,7 +26,7 @@ pub struct Mutations<'a> {
     /// Any templates encountered while diffing the DOM.
     ///
     /// These must be loaded into a cache before applying the edits
-    pub templates: Vec<Template<'static>>,
+    pub templates: Vec<Template<'a>>,
 
     /// Any mutations required to patch the renderer to match the layout of the VirtualDom
     pub edits: Vec<Mutation<'a>>,

+ 2 - 2
packages/web/src/lib.rs

@@ -198,8 +198,9 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
             // todo: we need to split rebuild and initialize into two phases
             // it's a waste to produce edits just to get the vdom loaded
 
-            // we need to save the templates in case hydration fails
             let templates = dom.rebuild().templates;
+            websys_dom.load_templates(&templates);
+
             if let Err(err) = websys_dom.rehydrate(&dom) {
                 log::error!(
                     "Rehydration failed {:?}. Rebuild DOM into element from scratch",
@@ -209,7 +210,6 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
 
                 let edits = dom.rebuild();
 
-                websys_dom.load_templates(&templates);
                 websys_dom.load_templates(&edits.templates);
                 websys_dom.apply_edits(edits.edits);
             }