Skip to content

Commit c21a824

Browse files
committed
Remove Root component from playground-preview - return minimal HTML
The previous approach was completely wrong - it loaded the full Root component with Navbar, causing a nested website in the iframe and module resolution errors. Now returns a minimal HTML string directly: - No Root, no Navbar, no unnecessary components - Just critical color scheme script - Basic inline styles for dark/light mode - postMessage listener script - Clean preview area for user code This is what it should have been from the start. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9726eca commit c21a824

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

website/src/views/playground-preview.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import {jsx, Raw} from "@b9g/crank/standalone";
2-
import {Root} from "../components/root.js";
3-
import type {ViewProps} from "../router.js";
1+
import {Raw} from "@b9g/crank/standalone";
2+
import {getColorSchemeScript} from "../utils/color-scheme.js";
43

54
/**
6-
* Server-rendered view for playground preview iframes.
7-
* This loads as a proper server route with critical scripts,
5+
* Minimal server-rendered view for playground preview iframes.
6+
* This loads as a clean HTML page with critical scripts,
87
* then receives and executes user code via postMessage.
98
*/
10-
export default function* PlaygroundPreview({context: {storage}}: ViewProps) {
9+
export default function PlaygroundPreview() {
10+
const colorSchemeScript = getColorSchemeScript();
11+
1112
const scriptContent = `
1213
// Listen for code from parent window
1314
window.addEventListener("message", async (ev) => {
@@ -98,17 +99,38 @@ export default function* PlaygroundPreview({context: {storage}}: ViewProps) {
9899
);
99100
`;
100101

101-
yield jsx`
102-
<${Root}
103-
title="Playground Preview"
104-
description="Preview iframe for Crank.js playground"
105-
storage=${storage}
106-
url="/playground-preview"
107-
>
108-
<div id="preview-root"></div>
109-
<script type="module">
110-
<${Raw} value=${scriptContent} />
111-
</script>
112-
<//>
102+
return `
103+
<!DOCTYPE html>
104+
<html lang="en">
105+
<head>
106+
<meta charset="utf-8">
107+
<meta name="viewport" content="width=device-width,initial-scale=1">
108+
<script>${colorSchemeScript}</script>
109+
<style>
110+
html, body {
111+
background-color: #0a0e1f;
112+
color: #f5f9ff;
113+
margin: 0;
114+
padding: 0;
115+
font-family: sans-serif;
116+
}
117+
html.color-scheme-light, html.color-scheme-light body {
118+
background-color: #e7f4f5;
119+
color: #0a0e1f;
120+
}
121+
:root {
122+
--bg-color: #0a0e1f;
123+
--text-color: #f5f9ff;
124+
}
125+
.color-scheme-light {
126+
--bg-color: #e7f4f5;
127+
--text-color: #0a0e1f;
128+
}
129+
</style>
130+
</head>
131+
<body>
132+
<script type="module">${scriptContent}</script>
133+
</body>
134+
</html>
113135
`;
114136
}

0 commit comments

Comments
 (0)