Skip to content

feat(runtime-core): add generic option to getCurrentInstance #13407

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

Open
wants to merge 1 commit into
base: vapor
Choose a base branch
from
Open
Changes from all commits
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
21 changes: 18 additions & 3 deletions packages/runtime-core/src/componentCurrentInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,25 @@ export let currentInstance: GenericComponentInstance | null = null
export const getCurrentGenericInstance: () => GenericComponentInstance | null =
() => currentInstance || currentRenderingInstance

export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
currentInstance && !currentInstance.vapor
? (currentInstance as ComponentInternalInstance)
/**
* Retrieves the current component instance.
*
* @param generic - A boolean flag indicating whether to return a generic component instance.
* If `true`, returns a `GenericComponentInstance` including vapor instance.
* If `false` or unset, returns a `ComponentInternalInstance` if available.
* @returns The current component instance, or `null` if no instance is active.
*/
export function getCurrentInstance(
generic: true,
): GenericComponentInstance | null
export function getCurrentInstance(
generic?: boolean,
): ComponentInternalInstance | null
export function getCurrentInstance(generic?: boolean) {
return currentInstance && (generic || !currentInstance.vapor)
? currentInstance
: currentRenderingInstance
}

export let isInSSRComponentSetup = false

Expand Down