2
0
Эх сурвалжийг харах

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

daiwei 3 сар өмнө
parent
commit
d978639235

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

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