Skip to content

Commit 0bc363d

Browse files
committed
wip: slotScopeIds
1 parent 1169db8 commit 0bc363d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/runtime-vapor/__tests__/scopeId.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe('scopeId', () => {
200200
test.todo('should attach scopeId to suspense content', async () => {})
201201

202202
// :slotted basic
203-
test.todo('should work on slots', () => {
203+
test('should work on slots', () => {
204204
const Child = defineVaporComponent({
205205
__scopeId: 'child',
206206
setup() {

packages/runtime-vapor/src/block.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class VaporFragment {
2424
anchor?: Node
2525
insert?: (parent: ParentNode, anchor: Node | null) => void
2626
remove?: (parent?: ParentNode) => void
27+
scopeIds?: string[]
2728

2829
constructor(nodes: Block) {
2930
this.nodes = nodes
@@ -133,6 +134,12 @@ export function insert(
133134
insert(block.nodes, parent, anchor)
134135
}
135136
if (block.anchor) insert(block.anchor, parent, anchor)
137+
138+
if (block.scopeIds) {
139+
for (const scopeId of block.scopeIds) {
140+
setScopeId(block, scopeId)
141+
}
142+
}
136143
}
137144
}
138145

@@ -206,7 +213,6 @@ export function setScopeId(block: Block, scopeId: string): void {
206213
export function setComponentScopeId(instance: VaporComponentInstance): void {
207214
const parent = instance.parent
208215
if (!parent) return
209-
210216
if (isArray(instance.block) && instance.block.length > 1) return
211217

212218
const scopeId = parent.type.__scopeId

packages/runtime-vapor/src/componentSlots.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ export function createSlot(
156156
}
157157
}
158158

159+
const scopeIds: string[] = (fragment.scopeIds = [])
160+
const parentScopeId = instance.parent && instance.parent.type.__scopeId
161+
if (parentScopeId) scopeIds.push(parentScopeId)
162+
const scopeId = instance.type.__scopeId
163+
if (scopeId) scopeIds.push(`${scopeId}-s`)
164+
159165
if (!isHydrating && _insertionParent) {
160166
insert(fragment, _insertionParent, _insertionAnchor)
161167
}

0 commit comments

Comments
 (0)