fix(reactivity): computed should not trigger scheduler if stopped
fix #4149
This commit is contained in:
parent
dd0f9d1ce6
commit
6eb47f000a
@ -466,5 +466,25 @@ describe('reactivity/computed', () => {
|
||||
await tick
|
||||
expect(effectSpy).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
test('should not compute if deactivated before scheduler is called', async () => {
|
||||
const c1Spy = jest.fn()
|
||||
const src = ref(0)
|
||||
const c1 = computed(() => {
|
||||
c1Spy()
|
||||
return src.value % 2
|
||||
})
|
||||
effect(() => c1.value)
|
||||
expect(c1Spy).toHaveBeenCalledTimes(1)
|
||||
|
||||
// schedule stop
|
||||
schedule(() => {
|
||||
c1.effect.stop()
|
||||
})
|
||||
// trigger
|
||||
src.value++
|
||||
await tick
|
||||
expect(c1Spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -58,7 +58,7 @@ class ComputedRefImpl<T> {
|
||||
scheduled = true
|
||||
hasCompareTarget = false
|
||||
scheduler(() => {
|
||||
if (this._get() !== valueToCompare) {
|
||||
if (this.effect.active && this._get() !== valueToCompare) {
|
||||
triggerRefValue(this)
|
||||
}
|
||||
scheduled = false
|
||||
|
Loading…
Reference in New Issue
Block a user