File tree 2 files changed +27
-3
lines changed
test/unit/features/options
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,8 @@ if (__DEV__) {
51
51
*/
52
52
function mergeData (
53
53
to : Record < string | symbol , any > ,
54
- from : Record < string | symbol , any > | null
54
+ from : Record < string | symbol , any > | null ,
55
+ recursive = true
55
56
) : Record < PropertyKey , any > {
56
57
if ( ! from ) return to
57
58
let key , toVal , fromVal
@@ -66,7 +67,7 @@ function mergeData(
66
67
if ( key === '__ob__' ) continue
67
68
toVal = to [ key ]
68
69
fromVal = from [ key ]
69
- if ( ! hasOwn ( to , key ) ) {
70
+ if ( ! recursive || ! hasOwn ( to , key ) ) {
70
71
set ( to , key , fromVal )
71
72
} else if (
72
73
toVal !== fromVal &&
@@ -262,7 +263,22 @@ strats.props =
262
263
if ( childVal ) extend ( ret , childVal )
263
264
return ret
264
265
}
265
- strats . provide = mergeDataOrFn
266
+
267
+ strats . provide = function ( parentVal : Object | null , childVal : Object | null ) {
268
+ if ( ! parentVal ) return childVal
269
+ return function ( ) {
270
+ const ret = Object . create ( null )
271
+ mergeData ( ret , isFunction ( parentVal ) ? parentVal . call ( this ) : parentVal )
272
+ if ( childVal ) {
273
+ mergeData (
274
+ ret ,
275
+ isFunction ( childVal ) ? childVal . call ( this ) : childVal ,
276
+ false // non-recursive
277
+ )
278
+ }
279
+ return ret
280
+ }
281
+ }
266
282
267
283
/**
268
284
* Default strategy.
Original file line number Diff line number Diff line change @@ -712,4 +712,12 @@ describe('Options provide/inject', () => {
712
712
await nextTick ( )
713
713
expect ( spy ) . toHaveBeenCalledWith ( 2 )
714
714
} )
715
+
716
+ // #12854
717
+ test ( 'should not mutate original provide options' , ( ) => {
718
+ const hairMixin = { provide : { hair : 'red' } }
719
+ const eyesMixin = { provide : { eyes : 'brown' } }
720
+ new Vue ( { mixins : [ hairMixin , eyesMixin ] , render ( ) { } } ) . $mount ( )
721
+ expect ( eyesMixin . provide ) . toStrictEqual ( { eyes : 'brown' } )
722
+ } )
715
723
} )
You can’t perform that action at this time.
0 commit comments