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(
264
264
: oldValue ,
265
265
boundCleanup ,
266
266
]
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
+
267
276
call
268
277
? call ( cb ! , WatchErrorCodes . WATCH_CALLBACK , args )
269
278
: // @ts -expect-error
Original file line number Diff line number Diff line change @@ -868,6 +868,7 @@ export function createWatcher(
868
868
checkCompatEnabled ( DeprecationTypes . WATCH_ARRAY , instance )
869
869
) {
870
870
traverse ( val , 1 )
871
+ return { WATCH_ARRAY_UNWRAP : val }
871
872
}
872
873
return val
873
874
}
Original file line number Diff line number Diff line change @@ -69,6 +69,34 @@ test('WATCH_ARRAY', async () => {
69
69
expect ( spy ) . toHaveBeenCalledTimes ( 1 )
70
70
} )
71
71
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
+
72
100
test ( 'PROPS_DEFAULT_THIS' , ( ) => {
73
101
let thisCtx : any
74
102
const Child = {
You can’t perform that action at this time.
0 commit comments