From 11c95dbc50a55191595e4d98de33e1646ca34c8e Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 4 Dec 2025 15:22:22 +0800 Subject: [PATCH] refactor: extract scope ID retrieval into `getCurrentScopeId` helper. --- packages/runtime-vapor/src/component.ts | 11 +++++++---- packages/runtime-vapor/src/vdomInterop.ts | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index 4b59e30915..169c08ad5d 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -654,8 +654,7 @@ export class VaporComponentInstance implements GenericComponentInstance { : rawSlots : EMPTY_OBJ - const scopeOwner = getScopeOwner() - this.scopeId = scopeOwner && scopeOwner.type.__scopeId + this.scopeId = getCurrentScopeId() // apply custom element special handling if (comp.ce) { @@ -745,8 +744,7 @@ export function createPlainElement( ;(el as any).$root = isSingleRoot if (!isHydrating) { - const scopeOwner = getScopeOwner() - const scopeId = scopeOwner!.type.__scopeId + const scopeId = getCurrentScopeId() if (scopeId) setScopeId(el, [scopeId]) } @@ -1031,3 +1029,8 @@ function handleSetupResult( popWarningContext() } } + +export function getCurrentScopeId(): string | undefined { + const scopeOwner = getScopeOwner() + return scopeOwner && scopeOwner.type.__scopeId +} diff --git a/packages/runtime-vapor/src/vdomInterop.ts b/packages/runtime-vapor/src/vdomInterop.ts index a8ede59508..c6a0d98bbc 100644 --- a/packages/runtime-vapor/src/vdomInterop.ts +++ b/packages/runtime-vapor/src/vdomInterop.ts @@ -45,6 +45,7 @@ import { type VaporComponent, VaporComponentInstance, createComponent, + getCurrentScopeId, isVaporComponent, mountComponent, unmountComponent, @@ -60,7 +61,7 @@ import { } from '@vue/shared' import { type RawProps, rawPropsProxyHandlers } from './componentProps' import type { RawSlots, VaporSlot } from './componentSlots' -import { currentSlotScopeIds, getScopeOwner } from './componentSlots' +import { currentSlotScopeIds } from './componentSlots' import { renderEffect } from './renderEffect' import { _next, createTextNode } from './dom/node' import { optimizePropertyLookup } from './dom/prop' @@ -350,8 +351,7 @@ function createVDOMComponent( frag.nodes = vnode.el as any } - const scopeOwner = getScopeOwner() - vnode.scopeId = (scopeOwner && scopeOwner.type.__scopeId) || null + vnode.scopeId = getCurrentScopeId() || null vnode.slotScopeIds = currentSlotScopeIds frag.insert = (parentNode, anchor, transition) => { -- 2.47.3