File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,15 @@ export function watch(
264264 : oldValue ,
265265 boundCleanup ,
266266 ]
267+
268+ if ( __COMPAT__ ) {
269+ for ( let i = 0 ; i < args . length - 1 ; i ++ ) {
270+ if ( args [ i ] && args [ i ] . WATCH_ARRAY_UNWRAP ) {
271+ args [ i ] = args [ i ] . WATCH_ARRAY_UNWRAP
272+ }
273+ }
274+ }
275+
267276 call
268277 ? call ( cb ! , WatchErrorCodes . WATCH_CALLBACK , args )
269278 : // @ts -expect-error
Original file line number Diff line number Diff line change @@ -868,6 +868,7 @@ export function createWatcher(
868868 checkCompatEnabled ( DeprecationTypes . WATCH_ARRAY , instance )
869869 ) {
870870 traverse ( val , 1 )
871+ return { WATCH_ARRAY_UNWRAP : val }
871872 }
872873 return val
873874 }
Original file line number Diff line number Diff line change @@ -69,6 +69,34 @@ test('WATCH_ARRAY', async () => {
6969 expect ( spy ) . toHaveBeenCalledTimes ( 1 )
7070} )
7171
72+ test ( 'WATCH_ARRAY with non-array initial value' , async ( ) => {
73+ const spy = vi . fn ( )
74+ const vm = new Vue ( {
75+ data ( ) {
76+ return {
77+ foo : null ,
78+ }
79+ } ,
80+ watch : {
81+ foo : spy ,
82+ } ,
83+ } ) as any
84+ expect (
85+ deprecationData [ DeprecationTypes . WATCH_ARRAY ] . message ,
86+ ) . not . toHaveBeenWarned ( )
87+
88+ expect ( spy ) . not . toHaveBeenCalled ( )
89+ vm . foo = [ ]
90+ await nextTick ( )
91+ expect (
92+ deprecationData [ DeprecationTypes . WATCH_ARRAY ] . message ,
93+ ) . toHaveBeenWarned ( )
94+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
95+ vm . foo . push ( 1 )
96+ await nextTick ( )
97+ expect ( spy ) . toHaveBeenCalledTimes ( 2 )
98+ } )
99+
72100test ( 'PROPS_DEFAULT_THIS' , ( ) => {
73101 let thisCtx : any
74102 const Child = {
You can’t perform that action at this time.
0 commit comments