Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/compiler-vapor/src/generators/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function genCreateComponent(
const { helper } = context

const tag = genTag()
const { root, props, slots, once } = operation
const { root, props, slots, once, scopeId } = operation
const rawSlots = genRawSlots(slots, context)
const [ids, handlers] = processInlineHandlers(props, context)
const rawProps = context.withId(() => genRawProps(props, context), ids)
Expand All @@ -75,6 +75,7 @@ export function genCreateComponent(
rawSlots,
root ? 'true' : false,
once && 'true',
scopeId && JSON.stringify(scopeId),
),
...genDirectivesForElement(operation.id, context),
]
Expand Down
1 change: 1 addition & 0 deletions packages/compiler-vapor/src/ir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export interface CreateComponentIRNode extends BaseIRNode {
dynamic?: SimpleExpressionNode
parent?: number
anchor?: number
scopeId?: string | null
append?: boolean
last?: boolean
}
Expand Down
1 change: 1 addition & 0 deletions packages/compiler-vapor/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function transformComponentElement(
root: singleRoot && !context.inVFor,
slots: [...context.slots],
once: context.inVOnce,
scopeId: context.inSlot ? context.options.scopeId : undefined,
dynamic: dynamicComponent,
}
context.slots = []
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime-core/src/apiCreateApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ export interface VaporInteropInterface {
transition: TransitionHooks,
): void

vdomMount: (component: ConcreteComponent, props?: any, slots?: any) => any
vdomMount: (
component: ConcreteComponent,
props?: any,
slots?: any,
scopeId?: string,
) => any
vdomUnmount: UnmountComponentFn
vdomSlot: (
slots: any,
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,12 @@ export { type VaporInteropInterface } from './apiCreateApp'
/**
* @internal
*/
export { type RendererInternals, MoveType, invalidateMount } from './renderer'
export {
type RendererInternals,
MoveType,
getInheritedScopeIds,
invalidateMount,
} from './renderer'
/**
* @internal
*/
Expand Down
78 changes: 54 additions & 24 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,30 +777,9 @@ function baseCreateRenderer(
hostSetScopeId(el, slotScopeIds[i])
}
}
let subTree = parentComponent && parentComponent.subTree
if (subTree) {
if (
__DEV__ &&
subTree.patchFlag > 0 &&
subTree.patchFlag & PatchFlags.DEV_ROOT_FRAGMENT
) {
subTree =
filterSingleRoot(subTree.children as VNodeArrayChildren) || subTree
}
if (
vnode === subTree ||
(isSuspense(subTree.type) &&
(subTree.ssContent === vnode || subTree.ssFallback === vnode))
) {
const parentVNode = parentComponent!.vnode!
setScopeId(
el,
parentVNode,
parentVNode.scopeId,
parentVNode.slotScopeIds,
parentComponent!.parent,
)
}
const inheritedScopeIds = getInheritedScopeIds(vnode, parentComponent)
for (let i = 0; i < inheritedScopeIds.length; i++) {
hostSetScopeId(el, inheritedScopeIds[i])
}
}

Expand Down Expand Up @@ -2792,3 +2771,54 @@ export function getVaporInterface(
}
return res!
}

/**
* shared between vdom and vapor
*/
export function getInheritedScopeIds(
vnode: VNode,
parentComponent: GenericComponentInstance | null,
): string[] {
const inheritedScopeIds: string[] = []

let currentParent = parentComponent
let currentVNode = vnode

while (currentParent) {
let subTree = currentParent.subTree
if (!subTree) break

if (
__DEV__ &&
subTree.patchFlag > 0 &&
subTree.patchFlag & PatchFlags.DEV_ROOT_FRAGMENT
) {
subTree =
filterSingleRoot(subTree.children as VNodeArrayChildren) || subTree
}

if (
currentVNode === subTree ||
(isSuspense(subTree.type) &&
(subTree.ssContent === currentVNode ||
subTree.ssFallback === currentVNode))
) {
const parentVNode = currentParent.vnode!

if (parentVNode.scopeId) {
inheritedScopeIds.push(parentVNode.scopeId)
}

if (parentVNode.slotScopeIds) {
inheritedScopeIds.push(...parentVNode.slotScopeIds)
}

currentVNode = parentVNode
currentParent = currentParent.parent
} else {
break
}
}

return inheritedScopeIds
}
Loading
Loading