fix(custom-element): optimize slot retrieval to avoid duplicates

This commit is contained in:
daiwei 2025-10-04 10:52:21 +08:00
parent c16f8a94c7
commit f41d16e6c7
1 changed files with 16 additions and 4 deletions

View File

@ -685,11 +685,23 @@ export class VueElement
if (this._teleportTargets) {
roots.push(...this._teleportTargets)
}
return roots.reduce<HTMLSlotElement[]>((res, i) => {
res.push(...Array.from(i.querySelectorAll('slot')))
return res
}, [])
const seen = new Set<HTMLSlotElement>()
const slots: HTMLSlotElement[] = []
for (const root of roots) {
const found = root.querySelectorAll<HTMLSlotElement>('slot')
for (let i = 0; i < found.length; i++) {
const slot = found[i]
if (!seen.has(slot)) {
seen.add(slot)
slots.push(slot)
}
}
}
return slots
}
/**
* @internal
*/