Skip to content

Commit ab7fd45

Browse files
committed
fix(runtime): preserve setupState return
1 parent 882c144 commit ab7fd45

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/runtime-utils/mount.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
1515
route?: RouteLocationRaw
1616
}
1717

18+
// TODO: improve return types
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
type SetupState = Record<string, any>
21+
1822
/**
1923
* `mountSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins. For example:
2024
*
@@ -44,7 +48,7 @@ export type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
4448
export async function mountSuspended<T>(
4549
component: T,
4650
options?: MountSuspendedOptions<T>,
47-
): Promise<ReturnType<typeof mount<T>> & { setupState: Record<string, unknown> }> {
51+
): Promise<ReturnType<typeof mount<T>> & { setupState: SetupState }> {
4852
const {
4953
props = {},
5054
attrs = {},
@@ -55,7 +59,7 @@ export async function mountSuspended<T>(
5559

5660
// @ts-expect-error untyped global __unctx__
5761
const vueApp = globalThis.__unctx__.get('nuxt-app').tryUse().vueApp
58-
const { render, setup } = component as DefineComponent<Record<string, unknown>, Record <string, unknown>>
62+
const { render, setup } = component as DefineComponent<Record<string, unknown>, Record<string, unknown>>
5963

6064
let setupContext: SetupContext
6165
let setupState: Record<string, unknown>
@@ -70,7 +74,7 @@ export async function mountSuspended<T>(
7074
if (setup) {
7175
const result = await setup(props, setupContext)
7276
setupState = result && typeof result === 'object' ? result : {}
73-
return setupState
77+
return result
7478
}
7579
}
7680

0 commit comments

Comments
 (0)