Skip to content

Commit c92b274

Browse files
committed
fix hydration and validation errors in theater app
- Fix hydration error on initial load by delaying rendering until the component is mounted on the client. This handles scenario initialization from URL query parameters correctly without server/client mismatch. - Fix Zod validation error (`Array must contain at least 1 element(s)`) by ensuring `A2UIViewer` is only rendered when the aggregated components list is not empty.
1 parent d50db0a commit c92b274

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

tools/composer/src/app/theater/page.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ function formatBytes(bytes: number): string {
5858
}
5959

6060
export default function TheaterPage() {
61+
const [mounted, setMounted] = useState(false);
6162
const [leftTab, setLeftTab] = useState<LeftTab>('data');
6263
const [mobileView, setMobileView] = useState<'left' | 'renderer'>('renderer');
6364
const [renderer, setRenderer] = useState<RendererType>(RENDERERS[0]);
65+
66+
useEffect(() => {
67+
setMounted(true);
68+
}, []);
6469
const [selectedScenario, setSelectedScenario] = useState<ScenarioId>(() => {
6570
const url = readURL();
6671
return (url.scenario && url.scenario in scenarios) ? url.scenario as ScenarioId : 'restaurant-booking';
@@ -134,6 +139,10 @@ export default function TheaterPage() {
134139
return () => window.removeEventListener('keydown', handleKeyDown);
135140
}, [playbackState, progress, totalChunks, play, pause, seek]);
136141

142+
if (!mounted) {
143+
return <div className="flex h-screen items-center justify-center bg-background text-foreground">Loading...</div>;
144+
}
145+
137146
return (
138147
<div className="flex h-screen flex-col overflow-hidden bg-background text-foreground font-sans selection:bg-primary/30">
139148
{/* Header */}
@@ -381,7 +390,7 @@ export default function TheaterPage() {
381390
<span className="text-[10px] text-muted-foreground font-mono">{selectedScenario}</span>
382391
</div>
383392
<div className="p-4 bg-dot-pattern">
384-
{activeMessages.length > 0 ? (
393+
{activeMessages.length > 0 && surfaceState.components.length > 0 ? (
385394
<div className="w-full flex items-start justify-center">
386395
<A2UIViewer
387396
root={surfaceState.root}

0 commit comments

Comments
 (0)