Skip to content

Commit bdba4bd

Browse files
committed
refactor: rename getSlotInstance to getScopeOwner and centralize scope owner retrieval
1 parent 985209c commit bdba4bd

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

packages/runtime-vapor/src/component.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ import {
7777
type RawSlots,
7878
type StaticSlots,
7979
type VaporSlot,
80-
currentSlotOwner,
8180
dynamicSlotsProxyHandlers,
81+
getScopeOwner,
8282
getSlot,
8383
setCurrentSlotOwner,
8484
} from './componentSlots'
@@ -654,9 +654,7 @@ export class VaporComponentInstance implements GenericComponentInstance {
654654
: rawSlots
655655
: EMPTY_OBJ
656656

657-
// Use currentSlotOwner for scopeId inheritance when inside a slot
658-
// This ensures components created in slots inherit the slot owner's scopeId
659-
const scopeOwner = currentSlotOwner || currentInstance
657+
const scopeOwner = getScopeOwner()
660658
this.scopeId = scopeOwner && scopeOwner.type.__scopeId
661659

662660
// apply custom element special handling
@@ -747,8 +745,7 @@ export function createPlainElement(
747745
;(el as any).$root = isSingleRoot
748746

749747
if (!isHydrating) {
750-
// Use currentSlotOwner for scopeId when inside a slot
751-
const scopeOwner = currentSlotOwner || currentInstance
748+
const scopeOwner = getScopeOwner()
752749
const scopeId = scopeOwner!.type.__scopeId
753750
if (scopeId) setScopeId(el, [scopeId])
754751
}

packages/runtime-vapor/src/componentSlots.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export function setCurrentSlotOwner(
145145
* Get the effective slot instance for accessing rawSlots and scopeId.
146146
* Prefers currentSlotOwner (if inside a slot), falls back to currentInstance.
147147
*/
148-
export function getSlotInstance(): VaporComponentInstance {
148+
export function getScopeOwner(): VaporComponentInstance {
149149
return (currentSlotOwner || currentInstance) as VaporComponentInstance
150150
}
151151

@@ -180,8 +180,7 @@ export function createSlot(
180180
const _isLastInsertion = isLastInsertion
181181
if (!isHydrating) resetInsertionState()
182182

183-
// Use slot owner if inside a slot (forwarded slots), otherwise use currentInstance
184-
const instance = getSlotInstance()
183+
const instance = getScopeOwner()
185184
const rawSlots = instance.rawSlots
186185
const slotProps = rawProps
187186
? new Proxy(rawProps, rawPropsProxyHandlers)

packages/runtime-vapor/src/vdomInterop.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
} from '@vue/shared'
6161
import { type RawProps, rawPropsProxyHandlers } from './componentProps'
6262
import type { RawSlots, VaporSlot } from './componentSlots'
63-
import { currentSlotScopeIds, getSlotInstance } from './componentSlots'
63+
import { currentSlotScopeIds, getScopeOwner } from './componentSlots'
6464
import { renderEffect } from './renderEffect'
6565
import { _next, createTextNode } from './dom/node'
6666
import { optimizePropertyLookup } from './dom/prop'
@@ -350,8 +350,7 @@ function createVDOMComponent(
350350
frag.nodes = vnode.el as any
351351
}
352352

353-
// Use currentSlotOwner for scopeId when inside a slot
354-
const scopeOwner = getSlotInstance()
353+
const scopeOwner = getScopeOwner()
355354
vnode.scopeId = (scopeOwner && scopeOwner.type.__scopeId) || null
356355
vnode.slotScopeIds = currentSlotScopeIds
357356

0 commit comments

Comments
 (0)