From: daiwei Date: Thu, 4 Dec 2025 06:09:18 +0000 (+0800) Subject: refactor: rename `getSlotInstance` to `getScopeOwner` and centralize scope owner... X-Git-Tag: v3.6.0-alpha.6~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=603dc8b10284383728576a0f0b404b69b7658bb8;p=thirdparty%2Fvuejs%2Fcore.git refactor: rename `getSlotInstance` to `getScopeOwner` and centralize scope owner retrieval --- diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index c1098e3879..4b59e30915 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -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]) } diff --git a/packages/runtime-vapor/src/componentSlots.ts b/packages/runtime-vapor/src/componentSlots.ts index 273f2569dd..175bcae339 100644 --- a/packages/runtime-vapor/src/componentSlots.ts +++ b/packages/runtime-vapor/src/componentSlots.ts @@ -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) diff --git a/packages/runtime-vapor/src/vdomInterop.ts b/packages/runtime-vapor/src/vdomInterop.ts index 64ece00d88..a8ede59508 100644 --- a/packages/runtime-vapor/src/vdomInterop.ts +++ b/packages/runtime-vapor/src/vdomInterop.ts @@ -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