From 1385e4a231f86336f5fca780c75bcf1e6e28ac64 Mon Sep 17 00:00:00 2001 From: zhiyuanzmj <260480378@qq.com> Date: Mon, 8 Dec 2025 16:26:12 +0800 Subject: [PATCH 1/3] feat(runtime-vapor): support setup fn and render fn co-usage --- packages/runtime-vapor/src/component.ts | 32 ++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index ae568ac3a1b..aa0969cb1d6 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -412,7 +412,7 @@ export function setupComponent( ) } } else { - handleSetupResult(setupResult, component, instance, setupFn) + handleSetupResult(setupResult, component, instance) } setActiveSub(prevSub) @@ -802,12 +802,7 @@ export function mountComponent( ) { const component = instance.type instance.suspense.registerDep(instance, setupResult => { - handleSetupResult( - setupResult, - component, - instance, - isFunction(component) ? component : component.setup, - ) + handleSetupResult(setupResult, component, instance) mountComponent(instance, parent, anchor) }) return @@ -952,7 +947,6 @@ function handleSetupResult( setupResult: any, component: VaporComponent, instance: VaporComponentInstance, - setupFn: VaporSetupFn | undefined, ) { if (__DEV__) { pushWarningContext(instance) @@ -980,12 +974,22 @@ function handleSetupResult( } else { // component has a render function but no setup function // (typically components with only a template and no state) - if (!setupFn && component.render) { - instance.block = callWithErrorHandling( - component.render, - instance, - ErrorCodes.RENDER_FUNCTION, - ) + // support setup fn and render fn co-usage for defineComponent expose + if (!isBlock(setupResult) && component.render) { + instance.setupState = setupResult + instance.block = + callWithErrorHandling( + component.render, + instance, + ErrorCodes.RENDER_FUNCTION, + [ + instance.setupState, + instance.props, + instance.emit, + instance.attrs, + instance.slots, + ], + ) || [] } else { // in prod result can only be block instance.block = setupResult as Block From 5929f338711d8de13dccd8f1ea90a485e0d7d3ca Mon Sep 17 00:00:00 2001 From: zhiyuanzmj <260480378@qq.com> Date: Mon, 8 Dec 2025 16:33:18 +0800 Subject: [PATCH 2/3] Update packages/runtime-vapor/src/component.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/runtime-vapor/src/component.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index aa0969cb1d6..42cdfd21f1b 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -972,8 +972,9 @@ function handleSetupResult( devRender(instance) } } else { - // component has a render function but no setup function - // (typically components with only a template and no state) + // component has a render function with either: + // - no setup function (components with only a template) + // - setup returning non-block state for use in render // support setup fn and render fn co-usage for defineComponent expose if (!isBlock(setupResult) && component.render) { instance.setupState = setupResult From f8be210d87786c05aaad42b53c31b776ea50add7 Mon Sep 17 00:00:00 2001 From: zhiyuanzmj <260480378@qq.com> Date: Mon, 8 Dec 2025 16:35:56 +0800 Subject: [PATCH 3/3] Update packages/runtime-vapor/src/component.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/runtime-vapor/src/component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index 42cdfd21f1b..d141de91a12 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -977,7 +977,7 @@ function handleSetupResult( // - setup returning non-block state for use in render // support setup fn and render fn co-usage for defineComponent expose if (!isBlock(setupResult) && component.render) { - instance.setupState = setupResult + instance.setupState = proxyRefs(setupResult) instance.block = callWithErrorHandling( component.render,