]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: remove `cacheFragment` function and rename `instance` to `block` in `innerC...
authordaiwei <daiwei521@126.com>
Tue, 6 Jan 2026 03:28:25 +0000 (11:28 +0800)
committerdaiwei <daiwei521@126.com>
Tue, 6 Jan 2026 03:28:25 +0000 (11:28 +0800)
packages/runtime-vapor/src/components/KeepAlive.ts

index 66e1d7a3ae8a42dc7a1860247433b6fa57096fa2..a2a3eb0719845549db4d2687fbb97aa99be6af99 100644 (file)
@@ -102,7 +102,7 @@ const KeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
 
     const innerCacheBlock = (
       key: CacheKey,
-      instance: VaporComponentInstance | VaporFragment,
+      block: VaporComponentInstance | VaporFragment,
     ) => {
       const { max } = props
 
@@ -118,8 +118,8 @@ const KeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
         }
       }
 
-      cache.set(key, instance)
-      current = instance
+      cache.set(key, block)
+      current = block
     }
 
     const cacheBlock = () => {
@@ -151,21 +151,6 @@ const KeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
       return true
     }
 
-    const cacheFragment = (fragment: DynamicFragment) => {
-      const [innerBlock, interop] = getInnerBlock(fragment.nodes)
-      if (!innerBlock || !shouldCache(innerBlock, props, interop)) return
-
-      let key: CacheKey
-      if (interop) {
-        innerBlock.vnode!.shapeFlag! |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
-        key = innerBlock.vnode!.type
-      } else {
-        innerBlock.shapeFlag! |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
-        key = innerBlock.type
-      }
-      innerCacheBlock(key, innerBlock)
-    }
-
     const pruneCache = (filter: (name: string) => boolean) => {
       cache.forEach((cached, key) => {
         const instance = getInstanceFromCache(cached)
@@ -255,7 +240,7 @@ const KeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
         },
       )
       ;(frag.onBeforeMount || (frag.onBeforeMount = [])).push(() =>
-        cacheFragment(frag),
+        processFragment(frag),
       )
       frag.getScope = key => {
         const scope = keptAliveScopes.get(key)