]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): keep previous effect scope
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Fri, 2 Feb 2024 22:15:46 +0000 (06:15 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Fri, 2 Feb 2024 22:15:51 +0000 (06:15 +0800)
packages/reactivity/src/effectScope.ts
playground/src/v-for.js

index 6a3eaec9fd51a1585d9d9edec44512988bee0cbe..b101a474807373c936d79caa3fe7b7c40f9c3458 100644 (file)
@@ -62,11 +62,13 @@ export class EffectScope {
     }
   }
 
+  prevScope: EffectScope | undefined
   /**
    * This should only be called on non-detached scopes
    * @internal
    */
   on() {
+    this.prevScope = activeEffectScope
     activeEffectScope = this
   }
 
@@ -75,7 +77,7 @@ export class EffectScope {
    * @internal
    */
   off() {
-    activeEffectScope = this.parent
+    activeEffectScope = this.prevScope
   }
 
   stop(fromParent?: boolean) {
index e1ff1e1a8446c0b09cb395fae2c432c0835d982d..b41e5976be869e44233b78b8687c5d75529e5360 100644 (file)
@@ -23,12 +23,16 @@ export default defineComponent({
           const container = document.createElement('li')
           append(container, node)
 
-          const update = () => {
+          renderEffect(() => {
             const [item, index] = block.s
             node.textContent = `${index}. ${item}`
-          }
-          renderEffect(update)
-          return [container, update]
+          })
+
+          renderEffect(() => {
+            const [item, index] = block.s
+            node.textContent = `${index}/ ${item}`
+          })
+          return container
         },
         (item, index) => index,
       )