File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,9 @@ export function createAppAPI<HostElement>(
179
179
hydrate ?: RootHydrateFunction
180
180
) : CreateAppFunction < HostElement > {
181
181
return function createApp ( rootComponent , rootProps = null ) {
182
+
183
+ rootComponent = { ...rootComponent }
184
+
182
185
if ( rootProps != null && ! isObject ( rootProps ) ) {
183
186
__DEV__ && warn ( `root props passed to app.mount() must be an object.` )
184
187
rootProps = null
Original file line number Diff line number Diff line change @@ -12,4 +12,27 @@ describe('createApp for dom', () => {
12
12
expect ( root . children . length ) . toBe ( 1 )
13
13
expect ( root . children [ 0 ] instanceof SVGElement ) . toBe ( true )
14
14
} )
15
+
16
+ // #4398
17
+ test ( 'should not mutate original Root options object' , ( ) => {
18
+
19
+ const originalObj = {
20
+ data ( ) {
21
+ return {
22
+ counter : 0
23
+ }
24
+ }
25
+ }
26
+
27
+ const handler = jest . fn ( ( msg , instance , trace ) => {
28
+ expect ( msg ) . toMatch ( `Component is missing template or render function` )
29
+ } )
30
+
31
+ const Root = { ...originalObj }
32
+
33
+ const app = createApp ( Root )
34
+ app . config . warnHandler = handler
35
+ app . mount ( document . createElement ( 'div' ) )
36
+ expect ( originalObj ) . toMatchObject ( Root ) // ensure no additional properties are added to Root
37
+ } )
15
38
} )
You can’t perform that action at this time.
0 commit comments