mirror of https://github.com/vuejs/core.git
fix(runtime-vapor): should not warn invalid watch source when directly watching props (#13384)
This commit is contained in:
parent
2250d415b9
commit
430216a9f5
|
@ -497,6 +497,36 @@ describe('component: props', () => {
|
||||||
expect(changeSpy).toHaveBeenCalledTimes(1)
|
expect(changeSpy).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should not warn invalid watch source when directly watching props', async () => {
|
||||||
|
const changeSpy = vi.fn()
|
||||||
|
const { render, html } = define({
|
||||||
|
props: {
|
||||||
|
foo: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setup(props: any) {
|
||||||
|
watch(props, changeSpy)
|
||||||
|
const t0 = template('<h1></h1>')
|
||||||
|
const n0 = t0()
|
||||||
|
renderEffect(() => {
|
||||||
|
setElementText(n0, String(props.foo))
|
||||||
|
})
|
||||||
|
return n0
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const foo = ref('foo')
|
||||||
|
render({ foo: () => foo.value })
|
||||||
|
expect(html()).toBe(`<h1>foo</h1>`)
|
||||||
|
expect('Invalid watch source').not.toHaveBeenWarned()
|
||||||
|
|
||||||
|
foo.value = 'bar'
|
||||||
|
await nextTick()
|
||||||
|
expect(html()).toBe(`<h1>bar</h1>`)
|
||||||
|
expect(changeSpy).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
test('support null in required + multiple-type declarations', () => {
|
test('support null in required + multiple-type declarations', () => {
|
||||||
const { render } = define({
|
const { render } = define({
|
||||||
props: {
|
props: {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
validateProps,
|
validateProps,
|
||||||
warn,
|
warn,
|
||||||
} from '@vue/runtime-dom'
|
} from '@vue/runtime-dom'
|
||||||
|
import { ReactiveFlags } from '@vue/reactivity'
|
||||||
import { normalizeEmitsOptions } from './componentEmits'
|
import { normalizeEmitsOptions } from './componentEmits'
|
||||||
import { renderEffect } from './renderEffect'
|
import { renderEffect } from './renderEffect'
|
||||||
|
|
||||||
|
@ -63,6 +64,9 @@ export function getPropsProxyHandlers(
|
||||||
: YES
|
: YES
|
||||||
|
|
||||||
const getProp = (instance: VaporComponentInstance, key: string | symbol) => {
|
const getProp = (instance: VaporComponentInstance, key: string | symbol) => {
|
||||||
|
// this enables direct watching of props and prevents `Invalid watch source` DEV warnings.
|
||||||
|
if (key === ReactiveFlags.IS_REACTIVE) return true
|
||||||
|
|
||||||
if (!isProp(key)) return
|
if (!isProp(key)) return
|
||||||
const rawProps = instance.rawProps
|
const rawProps = instance.rawProps
|
||||||
const dynamicSources = rawProps.$
|
const dynamicSources = rawProps.$
|
||||||
|
|
Loading…
Reference in New Issue