From 078e754eba96e3aeb92bbabb61e950d1812ff7a2 Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 4 Dec 2025 15:27:27 +0800 Subject: [PATCH] refactor: allow `getScopeOwner` to return null and add non-null assertion for instance access. --- packages/runtime-vapor/src/component.ts | 2 +- packages/runtime-vapor/src/componentSlots.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index 169c08ad5d..ae568ac3a1 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -1032,5 +1032,5 @@ function handleSetupResult( export function getCurrentScopeId(): string | undefined { const scopeOwner = getScopeOwner() - return scopeOwner && scopeOwner.type.__scopeId + return scopeOwner ? scopeOwner.type.__scopeId : undefined } diff --git a/packages/runtime-vapor/src/componentSlots.ts b/packages/runtime-vapor/src/componentSlots.ts index 175bcae339..b0c50917f6 100644 --- a/packages/runtime-vapor/src/componentSlots.ts +++ b/packages/runtime-vapor/src/componentSlots.ts @@ -145,8 +145,8 @@ export function setCurrentSlotOwner( * Get the effective slot instance for accessing rawSlots and scopeId. * Prefers currentSlotOwner (if inside a slot), falls back to currentInstance. */ -export function getScopeOwner(): VaporComponentInstance { - return (currentSlotOwner || currentInstance) as VaporComponentInstance +export function getScopeOwner(): VaporComponentInstance | null { + return (currentSlotOwner || currentInstance) as VaporComponentInstance | null } /** @@ -180,7 +180,7 @@ export function createSlot( const _isLastInsertion = isLastInsertion if (!isHydrating) resetInsertionState() - const instance = getScopeOwner() + const instance = getScopeOwner()! const rawSlots = instance.rawSlots const slotProps = rawProps ? new Proxy(rawProps, rawPropsProxyHandlers) -- 2.47.3