diff --git a/website-next/src/components/Playground.module.css b/website-next/src/components/Playground.module.css
index c1c6a3f4..9c89296e 100644
--- a/website-next/src/components/Playground.module.css
+++ b/website-next/src/components/Playground.module.css
@@ -101,6 +101,10 @@ html[data-theme='dark'] {
height: unset;
}
+ .playgroundEditor :global(.prism-code) {
+ min-height: 10em;
+ }
+
.playgroundRow {
flex-direction: column;
padding-inline: 5px;
diff --git a/website-next/src/components/Playground.tsx b/website-next/src/components/Playground.tsx
index dd0e6c75..9887eb30 100644
--- a/website-next/src/components/Playground.tsx
+++ b/website-next/src/components/Playground.tsx
@@ -28,16 +28,8 @@ import type {StyleNode} from './YogaViewer';
import styles from './Playground.module.css';
-const defaultCode = `
-
-
-
-
-
-`.trim();
-
export type Props = Readonly<{
- code?: string;
+ code: string;
height?: CSSProperties['height'];
autoFocus?: boolean;
}>;
@@ -46,7 +38,7 @@ export default function Playground({code, height, autoFocus}: Props) {
const prismTheme = usePrismTheme();
const editorScrollRef = useRef(null);
- const [liveCode, setLiveCode] = useState(code ?? defaultCode);
+ const [liveCode, setLiveCode] = useState(code);
const [hasCodeChanged, setHasCodeChanged] = useState(false);
const [scrollbarWidth, setScrollbarWidth] = useState(0);
diff --git a/website-next/src/pages/playground.tsx b/website-next/src/pages/playground.tsx
index 7522b6e7..d16be6f4 100644
--- a/website-next/src/pages/playground.tsx
+++ b/website-next/src/pages/playground.tsx
@@ -12,18 +12,44 @@ import lzString from 'lz-string';
import Playground from '../components/Playground';
import styles from './playground.module.css';
+import useIsBrowser from '@docusaurus/useIsBrowser';
+
+const defaultCode = `
+
+
+
+
+
+`.trim();
export default function PlaygroundPage(): JSX.Element {
- const params = new URLSearchParams(useLocation().search);
- const codeParam = params.get('code');
- const code = codeParam
- ? lzString.decompressFromEncodedURIComponent(codeParam)
- : undefined;
+ const code = useCodeFromQueryParam();
return (
// @ts-ignore missing prop for `wrapperClassName`
-
+
);
}
+
+function useCodeFromQueryParam(): string {
+ const location = useLocation();
+
+ // We don't know the query param ahead of time when doing SSR, so just render
+ // blank to avoid the appearance of code changing.
+ if (!useIsBrowser()) {
+ return '';
+ }
+
+ const params = new URLSearchParams(location.search);
+ const codeParam = params.get('code');
+ return codeParam
+ ? lzString.decompressFromEncodedURIComponent(codeParam)
+ : defaultCode;
+}