diff --git a/packages/runtime-core/__tests__/hmr.spec.ts b/packages/runtime-core/__tests__/hmr.spec.ts index 70af6485..4f1a5e5d 100644 --- a/packages/runtime-core/__tests__/hmr.spec.ts +++ b/packages/runtime-core/__tests__/hmr.spec.ts @@ -16,6 +16,8 @@ import { baseCompile } from '@vue/compiler-core' declare var __VUE_HMR_RUNTIME__: HMRRuntime const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__ +runtimeTest.registerRuntimeCompiler(compileToFunction) + function compileToFunction(template: string) { const { code } = baseCompile(template) const render = new Function('Vue', code)( diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 7b7ced57..8c1d55a2 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -10,12 +10,12 @@ import { import { ComponentPublicInstance, PublicInstanceProxyHandlers, - RuntimeCompiledPublicInstanceProxyHandlers, createRenderContext, exposePropsOnRenderContext, exposeSetupStateOnRenderContext, ComponentPublicInstanceConstructor, - publicPropertiesMap + publicPropertiesMap, + RuntimeCompiledPublicInstanceProxyHandlers } from './componentPublicInstance' import { ComponentPropsOptions, @@ -711,9 +711,7 @@ type CompileFunction = ( ) => InternalRenderFunction let compile: CompileFunction | undefined - -// dev only -export const isRuntimeOnly = () => !compile +let installWithProxy: (i: ComponentInternalInstance) => void /** * For runtime-dom to register the compiler. @@ -721,8 +719,16 @@ export const isRuntimeOnly = () => !compile */ export function registerRuntimeCompiler(_compile: any) { compile = _compile + installWithProxy = i => { + if (i.render!._rc) { + i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers) + } + } } +// dev only +export const isRuntimeOnly = () => !compile + export function finishComponentSetup( instance: ComponentInternalInstance, isSSR: boolean, @@ -792,11 +798,8 @@ export function finishComponentSetup( // for runtime-compiled render functions using `with` blocks, the render // proxy used needs a different `has` handler which is more performant and // also only allows a whitelist of globals to fallthrough. - if (instance.render._rc) { - instance.withProxy = new Proxy( - instance.ctx, - RuntimeCompiledPublicInstanceProxyHandlers - ) + if (installWithProxy) { + installWithProxy(instance) } } diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 1e5935b6..9c0eec14 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -224,7 +224,7 @@ const getPublicInstance = ( return getPublicInstance(i.parent) } -export const publicPropertiesMap: PublicPropertiesMap = extend( +export const publicPropertiesMap: PublicPropertiesMap = /*#__PURE__*/ extend( Object.create(null), { $: i => i, @@ -459,7 +459,7 @@ if (__DEV__ && !__TEST__) { } } -export const RuntimeCompiledPublicInstanceProxyHandlers = extend( +export const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend( {}, PublicInstanceProxyHandlers, {