Skip to content

Commit 6f8fe4e

Browse files
committed
wip: more compat tweaks
1 parent 7e0224a commit 6f8fe4e

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DeprecationTypes, isCompatEnabled } from './compatConfig'
44

55
export function shouldSkipAttr(
66
key: string,
7+
value: any,
78
instance: ComponentInternalInstance
89
): boolean {
910
if (
@@ -18,5 +19,9 @@ export function shouldSkipAttr(
1819
) {
1920
return true
2021
}
22+
// vue-router
23+
if (key.startsWith('routerView') || key === 'registerRouteInstance') {
24+
return true
25+
}
2126
return false
2227
}

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ export function createCompatVue(
153153

154154
// copy prototype augmentations as config.globalProperties
155155
if (isCompatEnabled(DeprecationTypes.GLOBAL_PROTOTYPE, null)) {
156-
app.config.globalProperties = extend(
157-
Object.create(Ctor.prototype),
158-
singletonApp.config.globalProperties
159-
)
156+
app.config.globalProperties = Ctor.prototype
160157
}
161158
let hasPrototypeAugmentations = false
162159
for (const key in Ctor.prototype) {
@@ -449,7 +446,9 @@ function defineReactive(obj: any, key: string, val: any) {
449446
})
450447
} else {
451448
Object.keys(val).forEach(key => {
452-
defineReactiveSimple(val, key, val[key])
449+
try {
450+
defineReactiveSimple(val, key, val[key])
451+
} catch (e) {}
453452
})
454453
}
455454
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
9393
$children: getCompatChildren,
9494
$listeners: getCompatListeners,
9595

96-
// inject parent into $options for compat
96+
$vnode: i => i.vnode,
97+
98+
// inject addtional properties into $options for compat
9799
$options: i => {
98100
let res = resolveMergedOptions(i)
99101
if (res === i.type) res = i.type.__merged = extend({}, res)
100102
res.parent = i.proxy!.$parent
103+
res.propsData = i.vnode.props
101104
return res
102105
},
103106

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

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
resolveDynamicComponent
2525
} from '../helpers/resolveAssets'
2626
import {
27+
Comment,
2728
createVNode,
2829
isVNode,
2930
normalizeChildren,
@@ -121,6 +122,10 @@ export function compatH(
121122
propsOrChildren?: any,
122123
children?: any
123124
): VNode {
125+
if (!type) {
126+
type = Comment
127+
}
128+
124129
// to support v2 string component name look!up
125130
if (typeof type === 'string') {
126131
const t = hyphenate(type)
@@ -201,6 +206,8 @@ function convertLegacyProps(
201206
}
202207
}
203208
}
209+
} else if (key === 'hook') {
210+
// TODO
204211
} else if (!skipLegacyRootLevelProps(key)) {
205212
converted[key] = legacyProps[key as keyof LegacyVNodeProps]
206213
}

packages/runtime-core/src/componentProps.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export function updateProps(
229229
)
230230
}
231231
} else {
232-
if (__COMPAT__ && shouldSkipAttr(key, instance)) {
232+
if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) {
233233
continue
234234
}
235235
if (value !== attrs[key]) {
@@ -337,7 +337,7 @@ function setFullProps(
337337
// Any non-declared (either as a prop or an emitted event) props are put
338338
// into a separate `attrs` object for spreading. Make sure to preserve
339339
// original key casing
340-
if (__COMPAT__ && shouldSkipAttr(key, instance)) {
340+
if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) {
341341
continue
342342
}
343343
if (value !== attrs[key]) {

packages/runtime-core/src/componentPublicInstance.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
345345
hasOwn(globalProperties, key))
346346
) {
347347
if (__COMPAT__) {
348-
const val = globalProperties[key]
349-
return isFunction(val) ? val.bind(instance.proxy) : val
348+
const desc = Object.getOwnPropertyDescriptor(globalProperties, key)!
349+
if (desc.get) {
350+
return desc.get.call(instance.proxy)
351+
} else {
352+
const val = globalProperties[key]
353+
return isFunction(val) ? val.bind(instance.proxy) : val
354+
}
350355
} else {
351356
return globalProperties[key]
352357
}

0 commit comments

Comments
 (0)