Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export function setupComponent(
)
}
} else {
handleSetupResult(setupResult, component, instance, setupFn)
handleSetupResult(setupResult, component, instance)
}

setActiveSub(prevSub)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -952,7 +947,6 @@ function handleSetupResult(
setupResult: any,
component: VaporComponent,
instance: VaporComponentInstance,
setupFn: VaporSetupFn | undefined,
) {
if (__DEV__) {
pushWarningContext(instance)
Expand Down Expand Up @@ -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) {
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing devtoolsRawSetupState assignment for production devtools support.

The dev-only path at lines 965-966 sets instance.devtoolsRawSetupState when __DEV__ || __FEATURE_PROD_DEVTOOLS__ is true. This production code path should have the same assignment to ensure devtools work correctly in production builds with devtools enabled.

Suggestion: Add before line 979:

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
  instance.devtoolsRawSetupState = setupResult
}
Suggested change
if (!isBlock(setupResult) && component.render) {
if (!isBlock(setupResult) && component.render) {
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
instance.devtoolsRawSetupState = setupResult
}

Copilot uses AI. Check for mistakes.
instance.setupState = setupResult
instance.block =
callWithErrorHandling(
component.render,
instance,
ErrorCodes.RENDER_FUNCTION,
[
instance.setupState,
instance.props,
instance.emit,
instance.attrs,
instance.slots,
],
) || []
Comment on lines 1035 to 1049
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage for the new setup + render co-usage functionality in production mode.

While there's an existing test at line 420 in component.spec.ts that tests setup + render together, it only verifies dev warnings for non-existent property access. The new production code path (lines 978-992) lacks test coverage for:

  1. Verifying that setupState properties (especially refs) are properly accessible and unwrapped in the render function in production mode
  2. Testing that the render function receives the correct parameters in the expected order
  3. Ensuring devtools integration works correctly with devtoolsRawSetupState

Consider adding a test that:

  • Sets __DEV__ = false
  • Creates a component with both setup (returning refs/reactive state) and render functions
  • Verifies the render function can access and use the setup state correctly

Copilot uses AI. Check for mistakes.
} else {
// in prod result can only be block
instance.block = setupResult as Block
Expand Down
Loading