Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(compat): fix app-level asset registration affecting other local a…
…pps (#5979)
  • Loading branch information
snoozbuster committed May 23, 2022
1 parent 7fbc933 commit 7fb5732
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/runtime-core/src/compat/global.ts
Expand Up @@ -381,9 +381,10 @@ function installLegacyAPIs(app: App) {

function applySingletonAppMutations(app: App) {
// copy over asset registries and deopt flag
;['mixins', 'components', 'directives', 'filters', 'deopt'].forEach(key => {
app._context.mixins = [...singletonApp._context.mixins]
;['components', 'directives', 'filters'].forEach(key => {
// @ts-ignore
app._context[key] = singletonApp._context[key]
app._context[key] = Object.create(singletonApp._context[key])
})

// copy over global config mutations
Expand Down
22 changes: 22 additions & 0 deletions packages/vue-compat/__tests__/global.spec.ts
Expand Up @@ -448,3 +448,25 @@ test('global asset registration should affect apps created via createApp', () =>
expect(vm.$el.textContent).toBe('foo')
delete singletonApp._context.components.foo
})

test('post-facto global asset registration should affect apps created via createApp', () => {
const app = createApp({
template: '<foo/>'
})
Vue.component('foo', { template: 'foo' })
const vm = app.mount(document.createElement('div')) as any;
expect(vm.$el.textContent).toBe('foo')
delete singletonApp._context.components.foo
})

test('local asset registration should not affect other local apps', () => {
const app1 = createApp({});
const app2 = createApp({});

app1.component('foo', {});
app2.component('foo', {});

expect(
`Component "foo" has already been registered in target app`
).not.toHaveBeenWarned()
})

0 comments on commit 7fb5732

Please sign in to comment.