]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: allow `getScopeOwner` to return null and add non-null assertion for instanc...
authordaiwei <daiwei521@126.com>
Thu, 4 Dec 2025 07:27:27 +0000 (15:27 +0800)
committeredison <daiwei521@126.com>
Thu, 4 Dec 2025 07:30:34 +0000 (15:30 +0800)
packages/runtime-vapor/src/component.ts
packages/runtime-vapor/src/componentSlots.ts

index 169c08ad5ddae5bf985fc981a6a096105dc479c5..ae568ac3a1b3b83d4606aac9ba9ee3ce66590f33 100644 (file)
@@ -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
 }
index 175bcae339292a8cdda65b11788984f1927cae79..b0c50917f64455d6c8a2b1c7168636edf3f44ac2 100644 (file)
@@ -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)