Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/client-mode-shell-end-marker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solidjs/vite-plugin': patch
---

Client start mode now strips the shell-end marker script along with the `<HydrationScript />` bootstrap. `@solidjs/web` 2.0.0-rc.15 (solidjs/solid#4002) closes every shell that rendered `<HydrationScript />` with `<script>_$HY.s[id]=1,…</script>`, and a Document shared with SSR mode carries `<HydrationScript />`. Once the plugin stripped the bootstrap, that marker threw `_$HY is not defined` in client-mode shells, in dev and in the prerendered `index.html`. Shells from earlier `@solidjs/web` versions have no marker and are unchanged.
14 changes: 13 additions & 1 deletion src/ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,20 @@ export function startServe(
);
}
lines.push(` chunk = chunk.replace('</head>', ${headParts.join(' + ')} + '</head>');`);
lines.push(` }`);
if (clientMode) {
// The shell-end marker (@solidjs/web 2.0.0-rc.15, solidjs/solid#4002)
// closes every shell that rendered `<HydrationScript />`. It writes to
// `_$HY` without a guard, so it goes with the bootstrap stripped above;
// left alone it throws `_$HY is not defined`. It follows the shell's
// records rather than its head, so it is matched in any chunk.
lines.push(
` if (chunk.includes('_$HY.s[')) {`,
` chunk = chunk.replace(/<script(?:\\s[^>]*)?>_\\$HY\\.s\\[[\\s\\S]*?<\\/script>/, '');`,
` }`,
);
}
lines.push(
` }`,
` if (first) { first = false; chunk = '<!DOCTYPE html>' + chunk; }`,
` return chunk;`,
` };`,
Expand Down
Loading