diff --git a/src/testing/html-serializer.ts b/src/testing/html-serializer.ts
index e18b0f1..d1a1e01 100644
--- a/src/testing/html-serializer.ts
+++ b/src/testing/html-serializer.ts
@@ -238,13 +238,18 @@ export function prettifyHtml(html: string): string {
lines.push(' '.repeat(indentLevel * indentSize) + part);
} else if (part.endsWith('/>')) {
- // Self-closing tag
+ // Self-closing tag (XML style)
lines.push(' '.repeat(indentLevel * indentSize) + part);
} else {
// Opening tag
lines.push(' '.repeat(indentLevel * indentSize) + part);
- // Increase indent for next content
- indentLevel++;
+
+ // Check if it's a void element - if so, don't increase indent
+ const tagName = part.match(/<([^\s>/]+)/)?.[1]?.toLowerCase();
+ if (!tagName || !VOID_ELEMENTS.has(tagName)) {
+ // Not a void element, increase indent for next content
+ indentLevel++;
+ }
}
} else {
// Text content - add on its own line with current indentation
diff --git a/test-project/src/components/non-shadow/__snapshots__/non-shadow-jsdom.spec.tsx.snap b/test-project/src/components/non-shadow/__snapshots__/non-shadow-jsdom.spec.tsx.snap
new file mode 100644
index 0000000..4a67c07
--- /dev/null
+++ b/test-project/src/components/non-shadow/__snapshots__/non-shadow-jsdom.spec.tsx.snap
@@ -0,0 +1,50 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`non-shadow-component serialization > nested components > should serialize nested non-shadow components 1`] = `
+
+ Main Content
+
+
+