Просмотр исходного кода

Fix temporary reads within rsx

Evan Almloff 1 год назад
Родитель
Сommit
b2607a5b35
1 измененных файлов с 10 добавлено и 6 удалено
  1. 10 6
      packages/rsx/src/lib.rs

+ 10 - 6
packages/rsx/src/lib.rs

@@ -244,12 +244,16 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
                 attr_paths: &[ #(#attr_paths),* ],
             };
 
-            dioxus_core::VNode::new(
-                #key_tokens,
-                TEMPLATE,
-                Box::new([ #( #node_printer),* ]),
-                Box::new([ #(#dyn_attr_printer),* ]),
-            )
+            {
+                // NOTE: Allocating a temporary is important to make reads within rsx drop before the value is returned
+                let __vnodes = dioxus_core::VNode::new(
+                    #key_tokens,
+                    TEMPLATE,
+                    Box::new([ #( #node_printer),* ]),
+                    Box::new([ #(#dyn_attr_printer),* ]),
+                );
+                __vnodes
+            }
         });
     }
 }