Skip to content

Commit 07a69da

Browse files
committed
wip: slotScopeIds
1 parent 1169db8 commit 07a69da

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

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: 13 additions & 6 deletions
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

@@ -203,16 +210,16 @@ export function setScopeId(block: Block, scopeId: string): void {
203210
}
204211
}
205212

206-
export function setComponentScopeId(instance: VaporComponentInstance): void {
213+
export function setComponentScopeId(
214+
instance: VaporComponentInstance,
215+
scopeId?: string,
216+
): void {
207217
const parent = instance.parent
208218
if (!parent) return
209-
210219
if (isArray(instance.block) && instance.block.length > 1) return
211220

212-
const scopeId = parent.type.__scopeId
213-
if (scopeId) {
214-
setScopeId(instance.block, scopeId)
215-
}
221+
if (!scopeId) scopeId = parent.type.__scopeId
222+
if (scopeId) setScopeId(instance.block, scopeId)
216223

217224
// inherit scopeId from vdom parent
218225
if (

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)