Pārlūkot izejas kodu

fix(runtime-vapor): fix scope preservation logic in onBeforeTeardown hooks

daiwei 4 mēneši atpakaļ
vecāks
revīzija
9675296b16
1 mainītis faili ar 6 papildinājumiem un 3 dzēšanām
  1. 6 3
      packages/runtime-vapor/src/fragment.ts

+ 6 - 3
packages/runtime-vapor/src/fragment.ts

@@ -118,6 +118,7 @@ export class DynamicFragment extends VaporFragment {
       if (isHydrating) this.hydrate(true)
       return
     }
+    const prevKey = this.current
     this.current = key
 
     const instance = currentInstance
@@ -130,9 +131,11 @@ export class DynamicFragment extends VaporFragment {
       // if any of the hooks returns true the scope will be preserved
       // for kept-alive component
       if (this.onBeforeTeardown) {
-        preserveScope = this.onBeforeTeardown.some(hook =>
-          hook(this.current, this.nodes, this.scope!),
-        )
+        for (const teardown of this.onBeforeTeardown) {
+          if (teardown(prevKey, this.nodes, this.scope!)) {
+            preserveScope = true
+          }
+        }
       }
       if (!preserveScope) {
         this.scope.stop()