Skip to content

Commit 94e69fd

Browse files
committed
fix(compat): handle and warn config.optionMergeStrategies
1 parent ed6c5fe commit 94e69fd

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const enum DeprecationTypes {
2626
CONFIG_PRODUCTION_TIP = 'CONFIG_PRODUCTION_TIP',
2727
CONFIG_IGNORED_ELEMENTS = 'CONFIG_IGNORED_ELEMENTS',
2828
CONFIG_WHITESPACE = 'CONFIG_WHITESPACE',
29+
CONFIG_OPTION_MERGE_STRATS = 'CONFIG_OPTION_MERGE_STRATS',
2930

3031
INSTANCE_SET = 'INSTANCE_SET',
3132
INSTANCE_DELETE = 'INSTANCE_DELETE',
@@ -174,6 +175,12 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
174175
`\`config.compilerOptions.whitespace\`.`
175176
},
176177

178+
[DeprecationTypes.CONFIG_OPTION_MERGE_STRATS]: {
179+
message:
180+
`config.optionMergeStrategies no longer exposes internal strategies. ` +
181+
`Use custom merge functions instead.`
182+
},
183+
177184
[DeprecationTypes.INSTANCE_SET]: {
178185
message:
179186
`vm.$set() has been removed as it is no longer needed in Vue 3. ` +

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import { Directive } from '../directives'
4141
import { nextTick } from '../scheduler'
4242
import { version } from '..'
4343
import {
44-
installLegacyConfigProperties,
44+
installLegacyConfigWarnings,
45+
installLegacyOptionMergeStrats,
4546
LegacyConfig,
4647
legacyOptionMergeStrats
4748
} from './globalConfig'
@@ -327,6 +328,7 @@ export function installAppCompatProperties(
327328
render: RootRenderFunction
328329
) {
329330
installFilterMethod(app, context)
331+
installLegacyOptionMergeStrats(app.config)
330332

331333
if (!singletonApp) {
332334
// this is the call of creating the singleton itself so the rest is
@@ -337,7 +339,7 @@ export function installAppCompatProperties(
337339
installCompatMount(app, context, render)
338340
installLegacyAPIs(app)
339341
applySingletonAppMutations(app)
340-
if (__DEV__) installLegacyConfigProperties(app.config)
342+
if (__DEV__) installLegacyConfigWarnings(app.config)
341343
}
342344

343345
function installFilterMethod(app: App, context: AppContext) {

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

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { extend, isArray } from '@vue/shared'
22
import { AppConfig } from '../apiCreateApp'
33
import { mergeDataOption } from './data'
4-
import { DeprecationTypes, warnDeprecation } from './compatConfig'
4+
import {
5+
DeprecationTypes,
6+
softAssertCompatEnabled,
7+
warnDeprecation
8+
} from './compatConfig'
59
import { isCopyingConfig } from './global'
610

711
// legacy config warnings
@@ -33,7 +37,7 @@ export type LegacyConfig = {
3337
}
3438

3539
// dev only
36-
export function installLegacyConfigProperties(config: AppConfig) {
40+
export function installLegacyConfigWarnings(config: AppConfig) {
3741
const legacyConfigOptions: Record<string, DeprecationTypes> = {
3842
silent: DeprecationTypes.CONFIG_SILENT,
3943
devtools: DeprecationTypes.CONFIG_DEVTOOLS,
@@ -57,11 +61,27 @@ export function installLegacyConfigProperties(config: AppConfig) {
5761
}
5862
})
5963
})
64+
}
6065

61-
// Internal merge strats which are no longer needed in v3, but we need to
62-
// expose them because some v2 plugins will reuse these internal strats to
63-
// merge their custom options.
64-
extend(config.optionMergeStrategies, legacyOptionMergeStrats)
66+
export function installLegacyOptionMergeStrats(config: AppConfig) {
67+
config.optionMergeStrategies = new Proxy({} as any, {
68+
get(target, key) {
69+
if (key in target) {
70+
return target[key]
71+
}
72+
if (
73+
key in legacyOptionMergeStrats &&
74+
softAssertCompatEnabled(
75+
DeprecationTypes.CONFIG_OPTION_MERGE_STRATS,
76+
null
77+
)
78+
) {
79+
return legacyOptionMergeStrats[
80+
key as keyof typeof legacyOptionMergeStrats
81+
]
82+
}
83+
}
84+
})
6585
}
6686

6787
export const legacyOptionMergeStrats = {

packages/vue-compat/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ Features that start with `COMPILER_` are compiler-specific: if you are using the
321321
| GLOBAL_OBSERVABLE || `Vue.observable` removed (use `reactive`) | [link](https://v3.vuejs.org/api/basic-reactivity.html) |
322322
| CONFIG_KEY_CODES || config.keyCodes rmeoved | [link](https://v3.vuejs.org/guide/migration/keycode-modifiers.html) |
323323
| CONFIG_WHITESPACE || In Vue 3 whitespace defaults to `"condense"` | |
324+
| CONFIG_OPTION_MERGE_STRATS || Vue 3 no longer exposes internal option merge strats | |
324325
| INSTANCE_SET || `vm.$set` removed (no longer needed) | |
325326
| INSTANCE_DELETE || `vm.$delete` removed (no longer needed) | |
326327
| INSTANCE_EVENT_EMITTER || `vm.$on`, `vm.$off`, `vm.$once` removed | [link](https://v3.vuejs.org/guide/migration/events-api.html) |

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Vue from '@vue/compat'
2-
import { toggleDeprecationWarning } from '../../runtime-core/src/compat/compatConfig'
2+
import {
3+
DeprecationTypes,
4+
toggleDeprecationWarning
5+
} from '../../runtime-core/src/compat/compatConfig'
36
import { createApp } from '../src/esm-index'
47
import { triggerEvent } from './utils'
58

@@ -74,3 +77,9 @@ test('singleton config should affect apps created with createApp()', () => {
7477
}).mount(el)
7578
expect(el.innerHTML).toBe(`<v-foo></v-foo><foo></foo>`)
7679
})
80+
81+
test('config.optionMergeStrategies', () => {
82+
toggleDeprecationWarning(true)
83+
expect(typeof Vue.config.optionMergeStrategies.created).toBe('function')
84+
expect(DeprecationTypes.CONFIG_OPTION_MERGE_STRATS).toHaveBeenWarned()
85+
})

0 commit comments

Comments
 (0)