Ver Fonte

fix(runtime-vapor): prevent fragment `updated` hooks from running before the fragment is mounted. (#14123)

edison há 5 meses atrás
pai
commit
b07fa60d5f

+ 1 - 1
packages/runtime-vapor/src/apiCreateFor.ts

@@ -403,7 +403,7 @@ export const createFor = (
       oldBlocks = []
     }
 
-    if (frag.updated) frag.updated.forEach(m => m())
+    if (isMounted && frag.updated) frag.updated.forEach(m => m())
     setActiveSub(prevSub)
   }
 

+ 2 - 1
packages/runtime-vapor/src/fragment.ts

@@ -191,7 +191,8 @@ export class DynamicFragment extends VaporFragment {
 
       if (parent) {
         insert(this.nodes, parent, this.anchor)
-        if (this.updated) {
+        // anchor isConnected indicates the this render is updated
+        if (this.anchor.isConnected && this.updated) {
           this.updated.forEach(hook => hook(this.nodes))
         }
       }

+ 2 - 2
packages/runtime-vapor/src/vdomInterop.ts

@@ -383,7 +383,7 @@ function createVDOMComponent(
     }
 
     frag.nodes = vnode.el as any
-    if (frag.updated) frag.updated.forEach(m => m())
+    if (isMounted && frag.updated) frag.updated.forEach(m => m())
   }
 
   frag.remove = unmount
@@ -450,7 +450,7 @@ function renderVDOMSlot(
       }
     }
 
-    if (frag.updated) frag.updated.forEach(m => m())
+    if (isMounted && frag.updated) frag.updated.forEach(m => m())
   }
 
   const render = (parentNode?: ParentNode, anchor?: Node | null) => {