-
-
Notifications
You must be signed in to change notification settings - Fork 9k
feat(runtime-vapor): support setup fn and render fn co-usage for defineVaporComponent #14179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: minor
Are you sure you want to change the base?
Changes from 1 commit
1385e4a
5929f33
f8be210
3e6130e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) { | ||||||||||||
|
||||||||||||
| if (!isBlock(setupResult) && component.render) { | |
| if (!isBlock(setupResult) && component.render) { | |
| if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { | |
| instance.devtoolsRawSetupState = setupResult | |
| } |
zhiyuanzmj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
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:
- Verifying that setupState properties (especially refs) are properly accessible and unwrapped in the render function in production mode
- Testing that the render function receives the correct parameters in the expected order
- 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
Uh oh!
There was an error while loading. Please reload this page.