File tree 2 files changed +34
-0
lines changed 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -497,6 +497,36 @@ describe('component: props', () => {
497
497
expect ( changeSpy ) . toHaveBeenCalledTimes ( 1 )
498
498
} )
499
499
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
+
500
530
test ( 'support null in required + multiple-type declarations' , ( ) => {
501
531
const { render } = define ( {
502
532
props : {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {
21
21
validateProps ,
22
22
warn ,
23
23
} from '@vue/runtime-dom'
24
+ import { ReactiveFlags } from '@vue/reactivity'
24
25
import { normalizeEmitsOptions } from './componentEmits'
25
26
import { renderEffect } from './renderEffect'
26
27
@@ -63,6 +64,9 @@ export function getPropsProxyHandlers(
63
64
: YES
64
65
65
66
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
+
66
70
if ( ! isProp ( key ) ) return
67
71
const rawProps = instance . rawProps
68
72
const dynamicSources = rawProps . $
You can’t perform that action at this time.
0 commit comments