]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compat): fix globalProperties pollution in v3 mode
authorEvan You <yyx990803@gmail.com>
Mon, 23 May 2022 01:46:00 +0000 (09:46 +0800)
committerEvan You <yyx990803@gmail.com>
Mon, 23 May 2022 01:46:00 +0000 (09:46 +0800)
fix #5699

packages/runtime-core/src/compat/global.ts
packages/vue-compat/__tests__/global.spec.ts

index 1cde73bd48aff39161b3903539995bc39fc36037..823181d23a7713ed7b82c3e74c99f7d48cd0f979 100644 (file)
@@ -399,7 +399,7 @@ function applySingletonAppMutations(app: App) {
     }
     const val = singletonApp.config[key as keyof AppConfig]
     // @ts-ignore
-    app.config[key] = val
+    app.config[key] = isObject(val) ? Object.create(val) : val
 
     // compat for runtime ignoredElements -> isCustomElement
     if (
index 0bc18a5d588d206b48c0d128b5545c17deed59c2..eda08d3026ecc91b7694f30dd00e01db61ab0952 100644 (file)
@@ -1,6 +1,6 @@
 import Vue from '@vue/compat'
 import { effect, isReactive } from '@vue/reactivity'
-import { nextTick } from '@vue/runtime-core'
+import { h, nextTick } from '@vue/runtime-core'
 import {
   DeprecationTypes,
   deprecationData,
@@ -454,19 +454,51 @@ test('post-facto global asset registration should affect apps created via create
     template: '<foo/>'
   })
   Vue.component('foo', { template: 'foo' })
-  const vm = app.mount(document.createElement('div')) as any;
+  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({});
+  const app1 = createApp({})
+  const app2 = createApp({})
 
-  app1.component('foo', {});
-  app2.component('foo', {});
+  app1.component('foo', {})
+  app2.component('foo', {})
 
   expect(
     `Component "foo" has already been registered in target app`
   ).not.toHaveBeenWarned()
-})
\ No newline at end of file
+})
+
+test('local app-level mixin registration should not affect other local apps', () => {
+  const app1 = createApp({ render: () => h('div') })
+  const app2 = createApp({})
+
+  const mixin = { created: jest.fn() }
+  app1.mixin(mixin)
+  app2.mixin(mixin)
+
+  expect(`Mixin has already been applied`).not.toHaveBeenWarned()
+
+  app1.mount(document.createElement('div'))
+  expect(mixin.created).toHaveBeenCalledTimes(1)
+})
+
+// #5699
+test('local app config should not affect other local apps in v3 mode', () => {
+  Vue.configureCompat({ MODE: 3 })
+  const app1 = createApp({
+    render: () => h('div'),
+    provide() {
+      return {
+        test: 123
+      }
+    }
+  })
+  app1.config.globalProperties.test = () => {}
+  app1.mount(document.createElement('div'))
+
+  const app2 = createApp({})
+  expect(app2.config.globalProperties.test).toBe(undefined)
+})