fix(reactivity): ensure computed always expose value
fix #3099 Also changes the original fix for #910 by moving the fix from reactivity to the scheduler
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { effect, stop } from '@vue/reactivity'
|
||||
import {
|
||||
queueJob,
|
||||
nextTick,
|
||||
@@ -568,4 +569,27 @@ describe('scheduler', () => {
|
||||
await nextTick()
|
||||
expect(count).toBe(1)
|
||||
})
|
||||
|
||||
// #910
|
||||
test('should not run stopped reactive effects', async () => {
|
||||
const spy = jest.fn()
|
||||
|
||||
// simulate parent component that toggles child
|
||||
const job1 = () => {
|
||||
stop(job2)
|
||||
}
|
||||
job1.id = 0 // need the id to ensure job1 is sorted before job2
|
||||
|
||||
// simulate child that's triggered by the same reactive change that
|
||||
// triggers its toggle
|
||||
const job2 = effect(() => spy())
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
|
||||
queueJob(job1)
|
||||
queueJob(job2)
|
||||
await nextTick()
|
||||
|
||||
// should not be called again
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user