wip: fix render fn compat detection
This commit is contained in:
@@ -30,6 +30,11 @@ export function isCompatEnabled(
|
||||
key: DeprecationTypes,
|
||||
instance: ComponentInternalInstance | null
|
||||
): boolean {
|
||||
// skip compat for built-in components
|
||||
if (instance && instance.type.__isBuiltIn) {
|
||||
return false
|
||||
}
|
||||
|
||||
const mode = getCompatConfigForKey('MODE', instance) || 2
|
||||
const val = getCompatConfigForKey(key, instance)
|
||||
if (mode === 2) {
|
||||
|
||||
@@ -19,6 +19,10 @@ export function convertLegacyComponent(
|
||||
comp: any,
|
||||
instance: ComponentInternalInstance | null
|
||||
): Component {
|
||||
if (comp.__isBuiltIn) {
|
||||
return comp
|
||||
}
|
||||
|
||||
// 2.x async component
|
||||
// since after disabling this, plain functions are still valid usage, do not
|
||||
// use softAssert here.
|
||||
|
||||
@@ -49,7 +49,11 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
|
||||
|
||||
// overrides existing accessor
|
||||
$slots: i => {
|
||||
if (isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, i)) {
|
||||
if (
|
||||
isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, i) &&
|
||||
i.render &&
|
||||
i.render._compatWrapped
|
||||
) {
|
||||
return new Proxy(i.slots, legacySlotProxyHandlers)
|
||||
}
|
||||
return __DEV__ ? shallowReadonly(i.slots) : i.slots
|
||||
|
||||
@@ -5,7 +5,13 @@ import {
|
||||
ShapeFlags,
|
||||
toHandlerKey
|
||||
} from '@vue/shared'
|
||||
import { Component, Data } from '../component'
|
||||
import {
|
||||
Component,
|
||||
ComponentInternalInstance,
|
||||
ComponentOptions,
|
||||
Data,
|
||||
InternalRenderFunction
|
||||
} from '../component'
|
||||
import { DirectiveArguments, withDirectives } from '../directives'
|
||||
import {
|
||||
resolveDirective,
|
||||
@@ -19,6 +25,35 @@ import {
|
||||
VNodeArrayChildren,
|
||||
VNodeProps
|
||||
} from '../vnode'
|
||||
import { checkCompatEnabled } from './compatConfig'
|
||||
import { DeprecationTypes } from './deprecations'
|
||||
|
||||
export function convertLegacyRenderFn(instance: ComponentInternalInstance) {
|
||||
const Component = instance.type as ComponentOptions
|
||||
const render = Component.render as InternalRenderFunction | undefined
|
||||
|
||||
// v3 runtime compiled, or already checked / wrapped
|
||||
if (!render || render._rc || render._compatChecked || render._compatWrapped) {
|
||||
return
|
||||
}
|
||||
|
||||
const string = render.toString()
|
||||
if (string.startsWith('function render(_ctx') || string.startsWith('(_ctx')) {
|
||||
// v3 pre-compiled function
|
||||
render._compatChecked = true
|
||||
return
|
||||
}
|
||||
|
||||
// v2 render function, try to provide compat
|
||||
if (checkCompatEnabled(DeprecationTypes.RENDER_FUNCTION, instance)) {
|
||||
const wrapped = (Component.render = function compatRender() {
|
||||
// @ts-ignore
|
||||
return render.call(this, compatH)
|
||||
})
|
||||
// @ts-ignore
|
||||
wrapped._compatWrapped = true
|
||||
}
|
||||
}
|
||||
|
||||
interface LegacyVNodeProps {
|
||||
key?: string | number
|
||||
|
||||
Reference in New Issue
Block a user