@@ -70,6 +70,7 @@ import {
7070 type StaticSlots ,
7171 type VaporSlot ,
7272 dynamicSlotsProxyHandlers ,
73+ getParentInstance ,
7374 getSlot ,
7475} from './componentSlots'
7576import { hmrReload , hmrRerender } from './hmr'
@@ -178,9 +179,7 @@ export function createComponent(
178179 rawSlots ?: LooseRawSlots | null ,
179180 isSingleRoot ?: boolean ,
180181 once ?: boolean ,
181- appContext : GenericAppContext = ( currentInstance &&
182- currentInstance . appContext ) ||
183- emptyContext ,
182+ appContext : GenericAppContext = emptyContext ,
184183) : VaporComponentInstance {
185184 const _insertionParent = insertionParent
186185 const _insertionAnchor = insertionAnchor
@@ -191,15 +190,23 @@ export function createComponent(
191190 resetInsertionState ( )
192191 }
193192
193+ const parentInstance = getParentInstance ( )
194+ appContext =
195+ appContext !== emptyContext
196+ ? appContext
197+ : parentInstance
198+ ? parentInstance . appContext
199+ : emptyContext
200+
194201 if (
195202 isSingleRoot &&
196203 component . inheritAttrs !== false &&
197- isVaporComponent ( currentInstance ) &&
198- currentInstance . hasFallthrough
204+ isVaporComponent ( parentInstance ) &&
205+ parentInstance . hasFallthrough
199206 ) {
200207 // check if we are the single root of the parent
201208 // if yes, inject parent attrs as dynamic props source
202- const attrs = currentInstance . attrs
209+ const attrs = parentInstance . attrs
203210 if ( rawProps ) {
204211 ; ( ( rawProps as RawProps ) . $ || ( ( rawProps as RawProps ) . $ = [ ] ) ) . push (
205212 ( ) => attrs ,
@@ -210,12 +217,8 @@ export function createComponent(
210217 }
211218
212219 // keep-alive
213- if (
214- currentInstance &&
215- currentInstance . vapor &&
216- isKeepAlive ( currentInstance )
217- ) {
218- const cached = ( currentInstance as KeepAliveInstance ) . getCachedComponent (
220+ if ( parentInstance && parentInstance . vapor && isKeepAlive ( parentInstance ) ) {
221+ const cached = ( parentInstance as KeepAliveInstance ) . getCachedComponent (
219222 component ,
220223 )
221224 // @ts -expect-error
@@ -262,6 +265,7 @@ export function createComponent(
262265 rawSlots as RawSlots ,
263266 appContext ,
264267 once ,
268+ parentInstance ,
265269 )
266270
267271 // HMR
@@ -525,6 +529,9 @@ export class VaporComponentInstance implements GenericComponentInstance {
525529 ec ?: LifecycleHook // LifecycleHooks.ERROR_CAPTURED
526530 sp ?: LifecycleHook < ( ) => Promise < unknown > > // LifecycleHooks.SERVER_PREFETCH
527531
532+ // Render-context owner used for scopeId inheritance.
533+ scopeOwner ?: GenericComponentInstance | null
534+
528535 // dev only
529536 setupState ?: Record < string , any >
530537 devtoolsRawSetupState ?: any
@@ -541,17 +548,19 @@ export class VaporComponentInstance implements GenericComponentInstance {
541548 rawSlots ?: RawSlots | null ,
542549 appContext ?: GenericAppContext ,
543550 once ?: boolean ,
551+ parent : GenericComponentInstance | null = currentInstance ,
544552 ) {
545553 this . vapor = true
546554 this . uid = nextUid ( )
547555 this . type = comp
548- this . parent = currentInstance
549- this . root = currentInstance ? currentInstance . root : this
550-
551- if ( currentInstance ) {
552- this . appContext = currentInstance . appContext
553- this . provides = currentInstance . provides
554- this . ids = currentInstance . ids
556+ this . parent = parent
557+ this . scopeOwner = currentInstance
558+ this . root = parent ? parent . root : this
559+
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 )
0 commit comments