@@ -71,6 +71,8 @@ import {
7171 type VaporSlot ,
7272 dynamicSlotsProxyHandlers ,
7373 getSlot ,
74+ getSlotConsumer ,
75+ getSlotScopeOwner ,
7476} from './componentSlots'
7577import { hmrReload , hmrRerender } from './hmr'
7678import {
@@ -178,8 +180,10 @@ export function createComponent(
178180 rawSlots ?: LooseRawSlots | null ,
179181 isSingleRoot ?: boolean ,
180182 once ?: boolean ,
181- appContext : GenericAppContext = ( currentInstance &&
182- currentInstance . appContext ) ||
183+ appContext : GenericAppContext = ( ( ( getSlotScopeOwner ( ) as VaporComponentInstance | null ) ||
184+ ( currentInstance as VaporComponentInstance | null ) ) &&
185+ ( ( getSlotScopeOwner ( ) as VaporComponentInstance | null ) ||
186+ ( currentInstance as VaporComponentInstance | null ) ) ! . appContext ) ||
183187 emptyContext ,
184188) : VaporComponentInstance {
185189 const _insertionParent = insertionParent
@@ -191,15 +195,19 @@ export function createComponent(
191195 resetInsertionState ( )
192196 }
193197
198+ const parentInstance =
199+ ( getSlotConsumer ( ) as VaporComponentInstance | null ) ||
200+ ( currentInstance as VaporComponentInstance | null )
201+
194202 if (
195203 isSingleRoot &&
196204 component . inheritAttrs !== false &&
197- isVaporComponent ( currentInstance ) &&
198- currentInstance . hasFallthrough
205+ isVaporComponent ( parentInstance ) &&
206+ parentInstance . hasFallthrough
199207 ) {
200208 // check if we are the single root of the parent
201209 // if yes, inject parent attrs as dynamic props source
202- const attrs = currentInstance . attrs
210+ const attrs = parentInstance . attrs
203211 if ( rawProps ) {
204212 ; ( ( rawProps as RawProps ) . $ || ( ( rawProps as RawProps ) . $ = [ ] ) ) . push (
205213 ( ) => attrs ,
@@ -210,12 +218,8 @@ export function createComponent(
210218 }
211219
212220 // keep-alive
213- if (
214- currentInstance &&
215- currentInstance . vapor &&
216- isKeepAlive ( currentInstance )
217- ) {
218- const cached = ( currentInstance as KeepAliveInstance ) . getCachedComponent (
221+ if ( parentInstance && parentInstance . vapor && isKeepAlive ( parentInstance ) ) {
222+ const cached = ( parentInstance as KeepAliveInstance ) . getCachedComponent (
219223 component ,
220224 )
221225 // @ts -expect-error
@@ -262,6 +266,7 @@ export function createComponent(
262266 rawSlots as RawSlots ,
263267 appContext ,
264268 once ,
269+ parentInstance ,
265270 )
266271
267272 // HMR
@@ -475,6 +480,9 @@ export class VaporComponentInstance implements GenericComponentInstance {
475480
476481 slots : StaticSlots
477482
483+ // slot template owner for scope inheritance
484+ slotScopeOwner : VaporComponentInstance | null
485+
478486 // to hold vnode props / slots in vdom interop mode
479487 rawPropsRef ?: ShallowRef < any >
480488 rawSlotsRef ?: ShallowRef < any >
@@ -541,17 +549,18 @@ export class VaporComponentInstance implements GenericComponentInstance {
541549 rawSlots ?: RawSlots | null ,
542550 appContext ?: GenericAppContext ,
543551 once ?: boolean ,
552+ parent : GenericComponentInstance | null = currentInstance ,
544553 ) {
545554 this . vapor = true
546555 this . uid = nextUid ( )
547556 this . type = comp
548- this . parent = currentInstance
549- this . root = currentInstance ? currentInstance . root : this
557+ this . parent = parent
558+ this . root = parent ? parent . root : this
550559
551- if ( currentInstance ) {
552- this . appContext = currentInstance . appContext
553- this . provides = currentInstance . provides
554- this . ids = currentInstance . ids
560+ if ( parent ) {
561+ this . appContext = parent . appContext
562+ this . provides = parent . provides
563+ this . ids = parent . ids
555564 } else {
556565 this . appContext = appContext || emptyContext
557566 this . provides = Object . create ( this . appContext . provides )
@@ -600,6 +609,8 @@ export class VaporComponentInstance implements GenericComponentInstance {
600609 : rawSlots
601610 : EMPTY_OBJ
602611
612+ this . slotScopeOwner = getSlotScopeOwner ( ) as VaporComponentInstance | null
613+
603614 // apply custom element special handling
604615 if ( comp . ce ) {
605616 comp . ce ( this )
@@ -672,7 +683,8 @@ export function createPlainElement(
672683 ; ( el as any ) . $root = isSingleRoot
673684
674685 if ( ! isHydrating ) {
675- const scopeId = currentInstance ! . type . __scopeId
686+ const scopeOwner = getSlotScopeOwner ( ) || currentInstance
687+ const scopeId = scopeOwner && scopeOwner . type . __scopeId
676688 if ( scopeId ) setScopeId ( el , [ scopeId ] )
677689 }
678690
0 commit comments