Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@vue/compat] Prevent local asset registration from affecting other local apps (fix #5699) #5979

Merged
merged 5 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/runtime-core/src/compat/global.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()
})