Skip to content

Commit 649854b

Browse files
fix: dynamically merge the alive effects to new scope
1 parent 9be7cf7 commit 649854b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/store-util.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,18 @@ export function resetStoreState (store, state, hot) {
8282

8383
// dispose previously registered effect scope if there is one.
8484
if (oldScope) {
85-
// Keep the effect that already have dependencies from being killed,
86-
// which will set the existed computed property unreactive.
87-
oldScope.effects = oldScope.effects.filter(({ deps }) => !deps.length)
85+
const deadEffects = []
86+
oldScope.effects.forEach(effect => {
87+
if (effect.deps.length) {
88+
// Merge the effect that already have dependencies and prevent from being killed.
89+
scope.effects.push(effect)
90+
} else {
91+
// Collect the dead effects.
92+
deadEffects.push(effect)
93+
}
94+
})
95+
// Dispose the dead effects.
96+
oldScope.effects = deadEffects
8897
oldScope.stop()
8998
}
9099
}

0 commit comments

Comments
 (0)