Skip to content

Commit b0df00a

Browse files
committed
fix(runtime-vapor): should not warn invalid watch source when directly watching props
1 parent 1ef6e6e commit b0df00a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

packages/runtime-vapor/__tests__/componentProps.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,36 @@ describe('component: props', () => {
497497
expect(changeSpy).toHaveBeenCalledTimes(1)
498498
})
499499

500+
test('should not warn invalid watch source when directly watching props', async () => {
501+
const changeSpy = vi.fn()
502+
const { render, html } = define({
503+
props: {
504+
foo: {
505+
type: String,
506+
},
507+
},
508+
setup(props: any) {
509+
watch(props, changeSpy)
510+
const t0 = template('<h1></h1>')
511+
const n0 = t0()
512+
renderEffect(() => {
513+
setElementText(n0, String(props.foo))
514+
})
515+
return n0
516+
},
517+
})
518+
519+
const foo = ref('foo')
520+
render({ foo: () => foo.value })
521+
expect(html()).toBe(`<h1>foo</h1>`)
522+
expect('Invalid watch source').not.toHaveBeenWarned()
523+
524+
foo.value = 'bar'
525+
await nextTick()
526+
expect(html()).toBe(`<h1>bar</h1>`)
527+
expect(changeSpy).toHaveBeenCalledTimes(1)
528+
})
529+
500530
test('support null in required + multiple-type declarations', () => {
501531
const { render } = define({
502532
props: {

packages/runtime-vapor/src/componentProps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
validateProps,
2222
warn,
2323
} from '@vue/runtime-dom'
24+
import { ReactiveFlags } from '@vue/reactivity'
2425
import { normalizeEmitsOptions } from './componentEmits'
2526
import { renderEffect } from './renderEffect'
2627

@@ -63,6 +64,9 @@ export function getPropsProxyHandlers(
6364
: YES
6465

6566
const getProp = (instance: VaporComponentInstance, key: string | symbol) => {
67+
// this enables direct watching of props and prevents `Invalid watch source` DEV warnings.
68+
if (key === ReactiveFlags.IS_REACTIVE) return true
69+
6670
if (!isProp(key)) return
6771
const rawProps = instance.rawProps
6872
const dynamicSources = rawProps.$

0 commit comments

Comments
 (0)