fix(dev-server): preserve nested component named slots

This commit is contained in:
Clintchiz committed 2026-08-26 15:20:54 +05:30
1 parent 25a421c727
commit 1dd60ded0d
4 files changed
+37 -7

No files matched your search

+11 -5
View File
@@ -2622,8 +2622,9 @@ function extractSlots(inner: string): { named: Record<string, string>; def: stri
const named: Record<string, string> = {};
if (!inner.includes("data-slot=")) return { named, def: inner };
const SLOT_MOUNT_RE =
/<([A-Za-z][A-Za-z0-9-]*)\b([^>]*?\bdata-slot="([A-Za-z0-9_-]+)"[^>]*?)(\/?)>/;
// Only direct children belong to this mount. Descendant named slots belong
// to their own component (for example a splitter inside a shell's slot).
const SLOT_MOUNT_RE = /<([A-Za-z][A-Za-z0-9-]*)\b([^>]*?)(\/?)>/;
let def = "";
let i = 0;
for (;;) {
@@ -2634,11 +2635,16 @@ function extractSlots(inner: string): { named: Record<string, string>; def: stri
}
const tagStart = i + m.index;
def += inner.slice(i, tagStart);
const [open, tag, , name, selfClose] = m;
const [open, tag, attributes, selfClose] = m;
const name = /\bdata-slot="([A-Za-z0-9_-]+)"/.exec(attributes!)?.[1];
const openEnd = tagStart + open.length;
const { inner: content, end } =
selfClose === "/" ? { inner: "", end: openEnd } : readElementBody(inner, tag!, openEnd);
named[name!] = content;
selfClose === "/" ||
/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/i.test(tag!)
? { inner: "", end: openEnd }
: readElementBody(inner, tag!, openEnd);
if (name) named[name] = content;
else def += inner.slice(tagStart, end);
i = end;
}
return { named, def };