fix(reactivity): fix currentScope loss when running detached effect scope (#5575)

This commit is contained in:
Wei
2022-04-12 15:51:05 +08:00
committed by GitHub
parent cee1eafb4d
commit 0a301d4dab
2 changed files with 23 additions and 2 deletions

View File

@@ -8,7 +8,13 @@ export class EffectScope {
effects: ReactiveEffect[] = []
cleanups: (() => void)[] = []
/**
* only assinged by undetached scope
*/
parent: EffectScope | undefined
/**
* record undetached scopes
*/
scopes: EffectScope[] | undefined
/**
* track a child scope's index in its parent's scopes array for optimized
@@ -28,11 +34,12 @@ export class EffectScope {
run<T>(fn: () => T): T | undefined {
if (this.active) {
const currentEffectScope = activeEffectScope
try {
activeEffectScope = this
return fn()
} finally {
activeEffectScope = this.parent
activeEffectScope = currentEffectScope
}
} else if (__DEV__) {
warn(`cannot run an inactive effect scope.`)