]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compat): fix app-level asset registration affecting other local apps (#5979)
authorAlex Van Liew <snoozbuster@outlook.com>
Mon, 23 May 2022 01:41:39 +0000 (18:41 -0700)
committerGitHub <noreply@github.com>
Mon, 23 May 2022 01:41:39 +0000 (21:41 -0400)
packages/runtime-core/src/compat/global.ts
packages/vue-compat/__tests__/global.spec.ts

index e0fc699fa5f99d6fcaf02cc47b12a4dc82efe42a..1cde73bd48aff39161b3903539995bc39fc36037 100644 (file)
@@ -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
index e4cd30074da8f46ec29b7e51642ed58ef684e260..0bc18a5d588d206b48c0d128b5545c17deed59c2 100644 (file)
@@ -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()
+})
\ No newline at end of file