]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: extract scope ID retrieval into `getCurrentScopeId` helper.
authordaiwei <daiwei521@126.com>
Thu, 4 Dec 2025 07:22:22 +0000 (15:22 +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/vdomInterop.ts

index 4b59e30915c1da2c51c07310b946fd60571240d1..169c08ad5ddae5bf985fc981a6a096105dc479c5 100644 (file)
@@ -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
+}
index a8ede59508a866f31c751cc08b759d0c3f4c0b20..c6a0d98bbcc739baee1b71e68ecca21f8c976f60 100644 (file)
@@ -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) => {