@@ -77,10 +77,10 @@ import {
7777 type RawSlots ,
7878 type StaticSlots ,
7979 type VaporSlot ,
80+ currentSlotOwner ,
8081 dynamicSlotsProxyHandlers ,
81- getParentInstance ,
8282 getSlot ,
83- setCurrentSlotConsumer ,
83+ setCurrentSlotOwner ,
8484} from './componentSlots'
8585import { hmrReload , hmrRerender } from './hmr'
8686import {
@@ -202,24 +202,22 @@ export function createComponent(
202202 resetInsertionState ( )
203203 }
204204
205- const parentInstance = getParentInstance ( )
206-
207205 let prevSuspense : SuspenseBoundary | null = null
208- if ( __FEATURE_SUSPENSE__ && parentInstance && parentInstance . suspense ) {
209- prevSuspense = setParentSuspense ( parentInstance . suspense )
206+ if ( __FEATURE_SUSPENSE__ && currentInstance && currentInstance . suspense ) {
207+ prevSuspense = setParentSuspense ( currentInstance . suspense )
210208 }
211209
212210 if (
213211 ( isSingleRoot ||
214212 // transition has attrs fallthrough
215- ( parentInstance && isVaporTransition ( parentInstance ! . type ) ) ) &&
213+ ( currentInstance && isVaporTransition ( currentInstance ! . type ) ) ) &&
216214 component . inheritAttrs !== false &&
217- isVaporComponent ( parentInstance ) &&
218- parentInstance . hasFallthrough
215+ isVaporComponent ( currentInstance ) &&
216+ currentInstance . hasFallthrough
219217 ) {
220218 // check if we are the single root of the parent
221219 // if yes, inject parent attrs as dynamic props source
222- const attrs = parentInstance . attrs
220+ const attrs = currentInstance . attrs
223221 if ( rawProps && rawProps !== EMPTY_OBJ ) {
224222 ; ( ( rawProps as RawProps ) . $ || ( ( rawProps as RawProps ) . $ = [ ] ) ) . push (
225223 ( ) => attrs ,
@@ -230,8 +228,12 @@ export function createComponent(
230228 }
231229
232230 // keep-alive
233- if ( parentInstance && parentInstance . vapor && isKeepAlive ( parentInstance ) ) {
234- const cached = ( parentInstance as KeepAliveInstance ) . getCachedComponent (
231+ if (
232+ currentInstance &&
233+ currentInstance . vapor &&
234+ isKeepAlive ( currentInstance )
235+ ) {
236+ const cached = ( currentInstance as KeepAliveInstance ) . getCachedComponent (
235237 component ,
236238 )
237239 // @ts -expect-error
@@ -240,14 +242,12 @@ export function createComponent(
240242
241243 // vdom interop enabled and component is not an explicit vapor component
242244 if ( appContext . vapor && ! component . __vapor ) {
243- const prevSlotConsumer = setCurrentSlotConsumer ( null )
244245 const frag = appContext . vapor . vdomMount (
245246 component as any ,
246- parentInstance as any ,
247+ currentInstance as any ,
247248 rawProps ,
248249 rawSlots ,
249250 )
250- setCurrentSlotConsumer ( prevSlotConsumer )
251251 if ( ! isHydrating ) {
252252 if ( _insertionParent ) insert ( frag , _insertionParent , _insertionAnchor )
253253 } else {
@@ -280,11 +280,10 @@ export function createComponent(
280280 rawSlots as RawSlots ,
281281 appContext ,
282282 once ,
283- parentInstance ,
284283 )
285284
286- // set currentSlotConsumer to null to avoid affecting the child components
287- const prevSlotConsumer = setCurrentSlotConsumer ( null )
285+ // reset currentSlotOwner to null to avoid affecting the child components
286+ const prevSlotOwner = setCurrentSlotOwner ( null )
288287
289288 // HMR
290289 if ( __DEV__ ) {
@@ -347,12 +346,12 @@ export function createComponent(
347346 endMeasure ( instance , 'init' )
348347 }
349348
350- if ( __FEATURE_SUSPENSE__ && parentInstance && parentInstance . suspense ) {
349+ if ( __FEATURE_SUSPENSE__ && currentInstance && currentInstance . suspense ) {
351350 setParentSuspense ( prevSuspense )
352351 }
353352
354- // restore currentSlotConsumer to previous value after setupFn is called
355- setCurrentSlotConsumer ( prevSlotConsumer )
353+ // restore currentSlotOwner to previous value after setupFn is called
354+ setCurrentSlotOwner ( prevSlotOwner )
356355 onScopeDispose ( ( ) => unmountComponent ( instance ) , true )
357356
358357 if ( _insertionParent || isHydrating ) {
@@ -594,19 +593,19 @@ export class VaporComponentInstance implements GenericComponentInstance {
594593 rawSlots ?: RawSlots | null ,
595594 appContext ?: GenericAppContext ,
596595 once ?: boolean ,
597- parent : GenericComponentInstance | null = currentInstance ,
598596 ) {
599597 this . vapor = true
600598 this . uid = nextUid ( )
601599 this . type = comp
602- this . parent = parent
603- this . root = parent ? parent . root : this
600+ this . parent = currentInstance
604601
605- if ( parent ) {
606- this . appContext = parent . appContext
607- this . provides = parent . provides
608- this . ids = parent . ids
602+ if ( currentInstance ) {
603+ this . root = currentInstance . root
604+ this . appContext = currentInstance . appContext
605+ this . provides = currentInstance . provides
606+ this . ids = currentInstance . ids
609607 } else {
608+ this . root = this
610609 this . appContext = appContext || emptyContext
611610 this . provides = Object . create ( this . appContext . provides )
612611 this . ids = [ '' , 0 , 0 ]
@@ -655,7 +654,10 @@ export class VaporComponentInstance implements GenericComponentInstance {
655654 : rawSlots
656655 : EMPTY_OBJ
657656
658- this . scopeId = currentInstance && currentInstance . type . __scopeId
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
660+ this . scopeId = scopeOwner && scopeOwner . type . __scopeId
659661
660662 // apply custom element special handling
661663 if ( comp . ce ) {
@@ -745,7 +747,9 @@ export function createPlainElement(
745747 ; ( el as any ) . $root = isSingleRoot
746748
747749 if ( ! isHydrating ) {
748- const scopeId = currentInstance ! . type . __scopeId
750+ // Use currentSlotOwner for scopeId when inside a slot
751+ const scopeOwner = currentSlotOwner || currentInstance
752+ const scopeId = scopeOwner ! . type . __scopeId
749753 if ( scopeId ) setScopeId ( el , [ scopeId ] )
750754 }
751755
0 commit comments