Skip to content

Commit 4bfaee0

Browse files
fix: correct astro JSX patch target string for DSD SSR on MDX content
The patch search string was missing the closing paren from the case expression, causing it to silently fail. This resulted in custom elements authored in MDX files (all component previews) being rendered as plain HTML without Declarative Shadow DOM templates. DSD coverage: 72% -> 99% (1167/1617 -> 1788/1805 elements).
1 parent 76d8826 commit 4bfaee0

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

scripts/patch-astro.mjs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { readFileSync, writeFileSync } from 'node:fs';
22

33
const file = 'node_modules/astro/dist/runtime/server/jsx.js';
44
const content = readFileSync(file, 'utf8');
5-
const patched = content.replace(
6-
'vnode.type !== ClientOnlyPlaceholder:',
7-
"vnode.type !== ClientOnlyPlaceholder && !vnode.type.includes('-'):"
8-
);
95

10-
if (content === patched) {
11-
console.log('⚠️ Astro patch target not found — may already be fixed or changed');
6+
const original = 'vnode.type !== ClientOnlyPlaceholder):';
7+
const replacement = "vnode.type !== ClientOnlyPlaceholder && !vnode.type.includes('-')):";
8+
9+
if (content.includes(replacement)) {
10+
console.log('astro/jsx: patch already applied');
11+
} else if (content.includes(original)) {
12+
writeFileSync(file, content.replace(original, replacement));
13+
console.log('astro/jsx: patch applied');
1214
} else {
13-
writeFileSync(file, patched);
14-
console.log('✅ Patched astro JSX handler for custom element hydration');
15+
console.error('astro/jsx: patch failed — target string not found');
16+
process.exit(1);
1517
}

0 commit comments

Comments
 (0)