Преглед изворни кода

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

daiwei пре 5 месеци
родитељ
комит
9675296b16
1 измењених фајлова са 6 додато и 3 уклоњено
  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()