From 8dec243dc1182c1db5d2928633bb446c7e94abd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Sat, 3 Feb 2024 06:15:46 +0800 Subject: [PATCH] fix(reactivity): keep previous effect scope --- packages/reactivity/src/effectScope.ts | 4 +++- playground/src/v-for.js | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index 6a3eaec9f..b101a4748 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -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) { diff --git a/playground/src/v-for.js b/playground/src/v-for.js index e1ff1e1a8..b41e5976b 100644 --- a/playground/src/v-for.js +++ b/playground/src/v-for.js @@ -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, )