Skip to content

Commit 8dec243

Browse files
committed
fix(reactivity): keep previous effect scope
1 parent be65b98 commit 8dec243

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/reactivity/src/effectScope.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ export class EffectScope {
6262
}
6363
}
6464

65+
prevScope: EffectScope | undefined
6566
/**
6667
* This should only be called on non-detached scopes
6768
* @internal
6869
*/
6970
on() {
71+
this.prevScope = activeEffectScope
7072
activeEffectScope = this
7173
}
7274

@@ -75,7 +77,7 @@ export class EffectScope {
7577
* @internal
7678
*/
7779
off() {
78-
activeEffectScope = this.parent
80+
activeEffectScope = this.prevScope
7981
}
8082

8183
stop(fromParent?: boolean) {

playground/src/v-for.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ export default defineComponent({
2323
const container = document.createElement('li')
2424
append(container, node)
2525

26-
const update = () => {
26+
renderEffect(() => {
2727
const [item, index] = block.s
2828
node.textContent = `${index}. ${item}`
29-
}
30-
renderEffect(update)
31-
return [container, update]
29+
})
30+
31+
renderEffect(() => {
32+
const [item, index] = block.s
33+
node.textContent = `${index}/ ${item}`
34+
})
35+
return container
3236
},
3337
(item, index) => index,
3438
)

0 commit comments

Comments
 (0)