Skip to content

Commit 7fd3913

Browse files
committed
fix: resolve hydration mismatch and cap widget height
Defer CopilotChat render to client-only to avoid Radix UI generating different IDs on server vs client. Cap widget iframe height at 800px to reduce whitespace from MCP widgets with large viewports.
1 parent e20a409 commit 7fd3913

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

apps/app/src/app/page.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useEffect } from "react";
3+
import { useEffect, useState } from "react";
44
import { ExampleLayout } from "@/components/example-layout";
55
import { useGenerativeUIExamples, useExampleSuggestions } from "@/hooks";
66
import { ExplainerCardsPortal } from "@/components/explainer-cards";
@@ -11,6 +11,10 @@ export default function HomePage() {
1111
useGenerativeUIExamples();
1212
useExampleSuggestions();
1313

14+
// Defer CopilotChat to client-only to avoid Radix hydration ID mismatch
15+
const [mounted, setMounted] = useState(false);
16+
useEffect(() => setMounted(true), []);
17+
1418
// Widget bridge: handle openLink from widget iframes
1519
useEffect(() => {
1620
const handler = (e: MessageEvent) => {
@@ -75,11 +79,13 @@ export default function HomePage() {
7579
</div>
7680

7781
<ExampleLayout chatContent={
78-
<CopilotChat
79-
labels={{
80-
welcomeMessageText: "What do you want to visualize today?",
81-
}}
82-
/>
82+
mounted ? (
83+
<CopilotChat
84+
labels={{
85+
welcomeMessageText: "What do you want to visualize today?",
86+
}}
87+
/>
88+
) : null
8389
} />
8490
<ExplainerCardsPortal />
8591
</div>

apps/app/src/components/generative-ui/widget-renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ export function WidgetRenderer({ title, description, html }: WidgetRendererProps
455455
e.data?.type === "widget-resize" &&
456456
typeof e.data.height === "number"
457457
) {
458-
setHeight(Math.max(50, Math.min(e.data.height + 8, 4000)));
458+
setHeight(Math.max(50, Math.min(e.data.height + 8, 800)));
459459
}
460460
}, []);
461461

0 commit comments

Comments
 (0)