Skip to content

Commit

Permalink
fix(runtime): preserve setupState return
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Apr 17, 2024
1 parent 882c144 commit ab7fd45
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/runtime-utils/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
route?: RouteLocationRaw
}

// TODO: improve return types
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type SetupState = Record<string, any>

/**
* `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:
*
Expand Down Expand Up @@ -44,7 +48,7 @@ export type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
export async function mountSuspended<T>(
component: T,
options?: MountSuspendedOptions<T>,
): Promise<ReturnType<typeof mount<T>> & { setupState: Record<string, unknown> }> {
): Promise<ReturnType<typeof mount<T>> & { setupState: SetupState }> {
const {
props = {},
attrs = {},
Expand All @@ -55,7 +59,7 @@ export async function mountSuspended<T>(

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

let setupContext: SetupContext
let setupState: Record<string, unknown>
Expand All @@ -70,7 +74,7 @@ export async function mountSuspended<T>(
if (setup) {
const result = await setup(props, setupContext)
setupState = result && typeof result === 'object' ? result : {}
return setupState
return result
}
}

Expand Down

0 comments on commit ab7fd45

Please sign in to comment.