فهرست منبع

fix(runtime-vapor): ensure KeepAlive onBeforeUnmount cleans up all cached entries

daiwei 3 ماه پیش
والد
کامیت
d978639235
1فایلهای تغییر یافته به همراه6 افزوده شده و 6 حذف شده
  1. 6 6
      packages/runtime-vapor/src/components/KeepAlive.ts

+ 6 - 6
packages/runtime-vapor/src/components/KeepAlive.ts

@@ -350,10 +350,6 @@ const VaporKeepAliveImpl = defineVaporComponent({
     onBeforeUnmount(() => {
     onBeforeUnmount(() => {
       cache.forEach((cached, key) => {
       cache.forEach((cached, key) => {
         const instance = getInstanceFromCache(cached)
         const instance = getInstanceFromCache(cached)
-        if (!instance) return
-
-        resetCachedShapeFlag(cached)
-        cache.delete(key)
 
 
         // current instance will be unmounted as part of keep-alive's unmount
         // current instance will be unmounted as part of keep-alive's unmount
         if (current) {
         if (current) {
@@ -363,13 +359,17 @@ const VaporKeepAliveImpl = defineVaporComponent({
             currentBranchKey,
             currentBranchKey,
           )
           )
           if (currentKey === key) {
           if (currentKey === key) {
+            resetCachedShapeFlag(cached)
             // call deactivated hook
             // call deactivated hook
-            const da = instance.da
-            da && queuePostFlushCb(da)
+            if (instance) {
+              const da = instance.da
+              da && queuePostFlushCb(da)
+            }
             return
             return
           }
           }
         }
         }
 
 
+        resetCachedShapeFlag(cached)
         remove(cached, storageContainer)
         remove(cached, storageContainer)
       })
       })
       keptAliveScopes.forEach(scope => scope.stop())
       keptAliveScopes.forEach(scope => scope.stop())