Skip to content

Commit 7fb5732

Browse files
authored
fix(compat): fix app-level asset registration affecting other local apps (#5979)
1 parent 7fbc933 commit 7fb5732

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,10 @@ function installLegacyAPIs(app: App) {
381381

382382
function applySingletonAppMutations(app: App) {
383383
// copy over asset registries and deopt flag
384-
;['mixins', 'components', 'directives', 'filters', 'deopt'].forEach(key => {
384+
app._context.mixins = [...singletonApp._context.mixins]
385+
;['components', 'directives', 'filters'].forEach(key => {
385386
// @ts-ignore
386-
app._context[key] = singletonApp._context[key]
387+
app._context[key] = Object.create(singletonApp._context[key])
387388
})
388389

389390
// copy over global config mutations

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

+22
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,25 @@ test('global asset registration should affect apps created via createApp', () =>
448448
expect(vm.$el.textContent).toBe('foo')
449449
delete singletonApp._context.components.foo
450450
})
451+
452+
test('post-facto global asset registration should affect apps created via createApp', () => {
453+
const app = createApp({
454+
template: '<foo/>'
455+
})
456+
Vue.component('foo', { template: 'foo' })
457+
const vm = app.mount(document.createElement('div')) as any;
458+
expect(vm.$el.textContent).toBe('foo')
459+
delete singletonApp._context.components.foo
460+
})
461+
462+
test('local asset registration should not affect other local apps', () => {
463+
const app1 = createApp({});
464+
const app2 = createApp({});
465+
466+
app1.component('foo', {});
467+
app2.component('foo', {});
468+
469+
expect(
470+
`Component "foo" has already been registered in target app`
471+
).not.toHaveBeenWarned()
472+
})

0 commit comments

Comments
 (0)