mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
fix: remove wrong observe toggle, properly disable tracking in setup()
This commit is contained in:
parent
9d54f8bdfe
commit
2d67641656
@ -1,6 +1,6 @@
|
||||
import { Component } from 'types/component'
|
||||
import { PropOptions } from 'types/options'
|
||||
import { toggleObserving } from '../core/observer'
|
||||
import { popTarget, pushTarget } from '../core/observer/dep'
|
||||
import { def, invokeWithErrorHandling, isReserved, warn } from '../core/util'
|
||||
import VNode from '../core/vdom/vnode'
|
||||
import {
|
||||
@ -31,7 +31,7 @@ export function initSetup(vm: Component) {
|
||||
const ctx = (vm._setupContext = createSetupContext(vm))
|
||||
|
||||
setCurrentInstance(vm)
|
||||
toggleObserving(false)
|
||||
pushTarget()
|
||||
const setupResult = invokeWithErrorHandling(
|
||||
setup,
|
||||
null,
|
||||
@ -39,7 +39,7 @@ export function initSetup(vm: Component) {
|
||||
vm,
|
||||
`setup`
|
||||
)
|
||||
toggleObserving(true)
|
||||
popTarget()
|
||||
setCurrentInstance()
|
||||
|
||||
if (isFunction(setupResult)) {
|
||||
|
@ -267,4 +267,31 @@ describe('api: setup context', () => {
|
||||
}
|
||||
}).$mount()
|
||||
})
|
||||
|
||||
it('should not track dep accessed in setup', async () => {
|
||||
const spy = vi.fn()
|
||||
const msg = ref('hi')
|
||||
|
||||
const Child = {
|
||||
setup: () => {
|
||||
msg.value
|
||||
return () => {}
|
||||
}
|
||||
}
|
||||
|
||||
new Vue({
|
||||
setup() {
|
||||
return h => {
|
||||
spy()
|
||||
return h(Child)
|
||||
}
|
||||
}
|
||||
}).$mount()
|
||||
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
|
||||
msg.value = 'bye'
|
||||
await nextTick()
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user