From 6f8fe4eac9fe8f4aad71a829d20897dc676c155c Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 22 Apr 2021 17:30:54 -0400 Subject: [PATCH] wip: more compat tweaks --- packages/runtime-core/src/compat/attrsFallthrough.ts | 5 +++++ packages/runtime-core/src/compat/global.ts | 9 ++++----- packages/runtime-core/src/compat/instance.ts | 5 ++++- packages/runtime-core/src/compat/renderFn.ts | 7 +++++++ packages/runtime-core/src/componentProps.ts | 4 ++-- packages/runtime-core/src/componentPublicInstance.ts | 9 +++++++-- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/runtime-core/src/compat/attrsFallthrough.ts b/packages/runtime-core/src/compat/attrsFallthrough.ts index 56ffe160..a23890b6 100644 --- a/packages/runtime-core/src/compat/attrsFallthrough.ts +++ b/packages/runtime-core/src/compat/attrsFallthrough.ts @@ -4,6 +4,7 @@ import { DeprecationTypes, isCompatEnabled } from './compatConfig' export function shouldSkipAttr( key: string, + value: any, instance: ComponentInternalInstance ): boolean { if ( @@ -18,5 +19,9 @@ export function shouldSkipAttr( ) { return true } + // vue-router + if (key.startsWith('routerView') || key === 'registerRouteInstance') { + return true + } return false } diff --git a/packages/runtime-core/src/compat/global.ts b/packages/runtime-core/src/compat/global.ts index ca97117c..45b9a2ad 100644 --- a/packages/runtime-core/src/compat/global.ts +++ b/packages/runtime-core/src/compat/global.ts @@ -153,10 +153,7 @@ export function createCompatVue( // copy prototype augmentations as config.globalProperties if (isCompatEnabled(DeprecationTypes.GLOBAL_PROTOTYPE, null)) { - app.config.globalProperties = extend( - Object.create(Ctor.prototype), - singletonApp.config.globalProperties - ) + app.config.globalProperties = Ctor.prototype } let hasPrototypeAugmentations = false for (const key in Ctor.prototype) { @@ -449,7 +446,9 @@ function defineReactive(obj: any, key: string, val: any) { }) } else { Object.keys(val).forEach(key => { - defineReactiveSimple(val, key, val[key]) + try { + defineReactiveSimple(val, key, val[key]) + } catch (e) {} }) } } diff --git a/packages/runtime-core/src/compat/instance.ts b/packages/runtime-core/src/compat/instance.ts index bf1d2e2f..b105aafc 100644 --- a/packages/runtime-core/src/compat/instance.ts +++ b/packages/runtime-core/src/compat/instance.ts @@ -93,11 +93,14 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) { $children: getCompatChildren, $listeners: getCompatListeners, - // inject parent into $options for compat + $vnode: i => i.vnode, + + // inject addtional properties into $options for compat $options: i => { let res = resolveMergedOptions(i) if (res === i.type) res = i.type.__merged = extend({}, res) res.parent = i.proxy!.$parent + res.propsData = i.vnode.props return res }, diff --git a/packages/runtime-core/src/compat/renderFn.ts b/packages/runtime-core/src/compat/renderFn.ts index afaef39c..5fc574b0 100644 --- a/packages/runtime-core/src/compat/renderFn.ts +++ b/packages/runtime-core/src/compat/renderFn.ts @@ -24,6 +24,7 @@ import { resolveDynamicComponent } from '../helpers/resolveAssets' import { + Comment, createVNode, isVNode, normalizeChildren, @@ -121,6 +122,10 @@ export function compatH( propsOrChildren?: any, children?: any ): VNode { + if (!type) { + type = Comment + } + // to support v2 string component name look!up if (typeof type === 'string') { const t = hyphenate(type) @@ -201,6 +206,8 @@ function convertLegacyProps( } } } + } else if (key === 'hook') { + // TODO } else if (!skipLegacyRootLevelProps(key)) { converted[key] = legacyProps[key as keyof LegacyVNodeProps] } diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index c1568bda..5d38325d 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -229,7 +229,7 @@ export function updateProps( ) } } else { - if (__COMPAT__ && shouldSkipAttr(key, instance)) { + if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) { continue } if (value !== attrs[key]) { @@ -337,7 +337,7 @@ function setFullProps( // Any non-declared (either as a prop or an emitted event) props are put // into a separate `attrs` object for spreading. Make sure to preserve // original key casing - if (__COMPAT__ && shouldSkipAttr(key, instance)) { + if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) { continue } if (value !== attrs[key]) { diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 22022317..9610aad1 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -345,8 +345,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { hasOwn(globalProperties, key)) ) { if (__COMPAT__) { - const val = globalProperties[key] - return isFunction(val) ? val.bind(instance.proxy) : val + const desc = Object.getOwnPropertyDescriptor(globalProperties, key)! + if (desc.get) { + return desc.get.call(instance.proxy) + } else { + const val = globalProperties[key] + return isFunction(val) ? val.bind(instance.proxy) : val + } } else { return globalProperties[key] }