]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: rename `getSlotInstance` to `getScopeOwner` and centralize scope owner...
authordaiwei <daiwei521@126.com>
Thu, 4 Dec 2025 06:09:18 +0000 (14:09 +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
packages/runtime-vapor/src/vdomInterop.ts

index c1098e3879c4acb6fcd9a34c01e996b2487cf4ce..4b59e30915c1da2c51c07310b946fd60571240d1 100644 (file)
@@ -77,8 +77,8 @@ import {
   type RawSlots,
   type StaticSlots,
   type VaporSlot,
-  currentSlotOwner,
   dynamicSlotsProxyHandlers,
+  getScopeOwner,
   getSlot,
   setCurrentSlotOwner,
 } from './componentSlots'
@@ -654,9 +654,7 @@ export class VaporComponentInstance implements GenericComponentInstance {
         : rawSlots
       : EMPTY_OBJ
 
-    // Use currentSlotOwner for scopeId inheritance when inside a slot
-    // This ensures components created in slots inherit the slot owner's scopeId
-    const scopeOwner = currentSlotOwner || currentInstance
+    const scopeOwner = getScopeOwner()
     this.scopeId = scopeOwner && scopeOwner.type.__scopeId
 
     // apply custom element special handling
@@ -747,8 +745,7 @@ export function createPlainElement(
   ;(el as any).$root = isSingleRoot
 
   if (!isHydrating) {
-    // Use currentSlotOwner for scopeId when inside a slot
-    const scopeOwner = currentSlotOwner || currentInstance
+    const scopeOwner = getScopeOwner()
     const scopeId = scopeOwner!.type.__scopeId
     if (scopeId) setScopeId(el, [scopeId])
   }
index 273f2569dddf85a0aab5edf13f2158b4c8638852..175bcae339292a8cdda65b11788984f1927cae79 100644 (file)
@@ -145,7 +145,7 @@ 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 getSlotInstance(): VaporComponentInstance {
+export function getScopeOwner(): VaporComponentInstance {
   return (currentSlotOwner || currentInstance) as VaporComponentInstance
 }
 
@@ -180,8 +180,7 @@ export function createSlot(
   const _isLastInsertion = isLastInsertion
   if (!isHydrating) resetInsertionState()
 
-  // Use slot owner if inside a slot (forwarded slots), otherwise use currentInstance
-  const instance = getSlotInstance()
+  const instance = getScopeOwner()
   const rawSlots = instance.rawSlots
   const slotProps = rawProps
     ? new Proxy(rawProps, rawPropsProxyHandlers)
index 64ece00d88ac4663fed603cf199080b68317e1ea..a8ede59508a866f31c751cc08b759d0c3f4c0b20 100644 (file)
@@ -60,7 +60,7 @@ import {
 } from '@vue/shared'
 import { type RawProps, rawPropsProxyHandlers } from './componentProps'
 import type { RawSlots, VaporSlot } from './componentSlots'
-import { currentSlotScopeIds, getSlotInstance } from './componentSlots'
+import { currentSlotScopeIds, getScopeOwner } from './componentSlots'
 import { renderEffect } from './renderEffect'
 import { _next, createTextNode } from './dom/node'
 import { optimizePropertyLookup } from './dom/prop'
@@ -350,8 +350,7 @@ function createVDOMComponent(
     frag.nodes = vnode.el as any
   }
 
-  // Use currentSlotOwner for scopeId when inside a slot
-  const scopeOwner = getSlotInstance()
+  const scopeOwner = getScopeOwner()
   vnode.scopeId = (scopeOwner && scopeOwner.type.__scopeId) || null
   vnode.slotScopeIds = currentSlotScopeIds