Skip to content

Commit 2f07e34

Browse files
committed
fix(compat): fix globalProperties pollution in v3 mode
fix #5699
1 parent 108474e commit 2f07e34

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

packages/runtime-core/src/compat/global.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ function applySingletonAppMutations(app: App) {
399399
}
400400
const val = singletonApp.config[key as keyof AppConfig]
401401
// @ts-ignore
402-
app.config[key] = val
402+
app.config[key] = isObject(val) ? Object.create(val) : val
403403

404404
// compat for runtime ignoredElements -> isCustomElement
405405
if (

packages/vue-compat/__tests__/global.spec.ts

+39-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from '@vue/compat'
22
import { effect, isReactive } from '@vue/reactivity'
3-
import { nextTick } from '@vue/runtime-core'
3+
import { h, nextTick } from '@vue/runtime-core'
44
import {
55
DeprecationTypes,
66
deprecationData,
@@ -454,19 +454,51 @@ test('post-facto global asset registration should affect apps created via create
454454
template: '<foo/>'
455455
})
456456
Vue.component('foo', { template: 'foo' })
457-
const vm = app.mount(document.createElement('div')) as any;
457+
const vm = app.mount(document.createElement('div')) as any
458458
expect(vm.$el.textContent).toBe('foo')
459459
delete singletonApp._context.components.foo
460460
})
461461

462462
test('local asset registration should not affect other local apps', () => {
463-
const app1 = createApp({});
464-
const app2 = createApp({});
463+
const app1 = createApp({})
464+
const app2 = createApp({})
465465

466-
app1.component('foo', {});
467-
app2.component('foo', {});
466+
app1.component('foo', {})
467+
app2.component('foo', {})
468468

469469
expect(
470470
`Component "foo" has already been registered in target app`
471471
).not.toHaveBeenWarned()
472-
})
472+
})
473+
474+
test('local app-level mixin registration should not affect other local apps', () => {
475+
const app1 = createApp({ render: () => h('div') })
476+
const app2 = createApp({})
477+
478+
const mixin = { created: jest.fn() }
479+
app1.mixin(mixin)
480+
app2.mixin(mixin)
481+
482+
expect(`Mixin has already been applied`).not.toHaveBeenWarned()
483+
484+
app1.mount(document.createElement('div'))
485+
expect(mixin.created).toHaveBeenCalledTimes(1)
486+
})
487+
488+
// #5699
489+
test('local app config should not affect other local apps in v3 mode', () => {
490+
Vue.configureCompat({ MODE: 3 })
491+
const app1 = createApp({
492+
render: () => h('div'),
493+
provide() {
494+
return {
495+
test: 123
496+
}
497+
}
498+
})
499+
app1.config.globalProperties.test = () => {}
500+
app1.mount(document.createElement('div'))
501+
502+
const app2 = createApp({})
503+
expect(app2.config.globalProperties.test).toBe(undefined)
504+
})

0 commit comments

Comments
 (0)