]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat: replace `Fragment`'s `effects` property and `BlockFragment`'s `mounted` hook...
authordaiwei <daiwei521@126.com>
Thu, 20 Nov 2025 08:49:21 +0000 (16:49 +0800)
committerdaiwei <daiwei521@126.com>
Thu, 20 Nov 2025 08:49:21 +0000 (16:49 +0800)
packages/runtime-vapor/src/apiCreateFor.ts
packages/runtime-vapor/src/components/Teleport.ts
packages/runtime-vapor/src/fragment.ts
packages/runtime-vapor/src/vdomInterop.ts

index 927809096f16cfefafa3c2b6529698adc8a7ade9..f4a636d7758d497764645be3ae96609050732191 100644 (file)
@@ -402,7 +402,8 @@ export const createFor = (
     } else {
       oldBlocks = []
     }
-    if (frag.effects) frag.effects.forEach(effect => effect())
+
+    if (frag.updated) frag.updated.forEach(m => m())
     setActiveSub(prevSub)
   }
 
index 871da0a02cf1646bdb2bbabeb9c8647a2a5b0454..afa5536f4413f99bc77cbb8db622858afca5ff48 100644 (file)
@@ -104,11 +104,11 @@ export class TeleportFragment extends VaporFragment {
     // updateCssVars will be called when subtree changed
     if (this.parentComponent && this.parentComponent.ut) {
       if (isFragment(nodes)) {
-        ;(nodes.effects || (nodes.effects = [])).push(() => updateCssVars(this))
+        ;(nodes.updated || (nodes.updated = [])).push(() => updateCssVars(this))
       } else if (isArray(nodes)) {
         nodes.forEach(node => {
           if (isFragment(node)) {
-            ;(node.effects || (node.effects = [])).push(() =>
+            ;(node.updated || (node.updated = [])).push(() =>
               updateCssVars(this),
             )
           }
index d4fe3ff36adfb89464dd77c9a7ab57aff5ef01a1..df4891c32865ec37f44588165c236e28e0a29359 100644 (file)
@@ -52,8 +52,8 @@ export class VaporFragment<T extends Block = Block>
     refKey: string | undefined,
   ) => void
 
-  // effects to run after fragment render
-  effects?: (() => void)[]
+  // hooks
+  updated?: ((nodes?: Block) => void)[]
 
   constructor(nodes: T) {
     this.nodes = nodes
@@ -83,7 +83,6 @@ export class DynamicFragment extends VaporFragment {
     scope: EffectScope,
   ) => boolean)[]
   beforeMount?: ((newKey: any, nodes: Block, scope: EffectScope) => void)[]
-  mounted?: ((nodes: Block, scope: EffectScope) => void)[]
 
   constructor(anchorLabel?: string) {
     super([])
@@ -192,15 +191,14 @@ export class DynamicFragment extends VaporFragment {
 
       if (parent) {
         insert(this.nodes, parent, this.anchor)
-        if (this.mounted) {
-          this.mounted.forEach(hook => hook(this.nodes, this.scope!))
+        if (this.updated) {
+          this.updated.forEach(hook => hook(this.nodes))
         }
       }
     } else {
       this.scope = undefined
       this.nodes = []
     }
-    if (this.effects) this.effects.forEach(effect => effect())
   }
 
   hydrate = (isEmpty = false): void => {
index 8a6d2eae0096230e9ae3beacac9eff11e134702d..3c4a961f0c9004d9a1ea8d2fbcc012249d9c4c08 100644 (file)
@@ -383,7 +383,7 @@ function createVDOMComponent(
     }
 
     frag.nodes = vnode.el as any
-    if (frag.effects) frag.effects.forEach(effect => effect())
+    if (frag.updated) frag.updated.forEach(m => m())
   }
 
   frag.remove = unmount
@@ -450,7 +450,7 @@ function renderVDOMSlot(
       }
     }
 
-    if (frag.effects) frag.effects.forEach(effect => effect())
+    if (frag.updated) frag.updated.forEach(m => m())
   }
 
   const render = (parentNode?: ParentNode, anchor?: Node | null) => {