Skip to content

Commit 92fc981

Browse files
committed
fix: widget renderer infinite height growth (#64), update example prompts
- Break feedback loop in iframe height measurement by collapsing the content container before reading scrollHeight, so viewport-relative children don't inflate the measurement - Remove +8 padding from height setter that compounded each cycle - Replace "binary search" suggestion with "car axle" visualization
1 parent cd5eeef commit 92fc981

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,17 @@ window.addEventListener('message', function(e) {
455455
}
456456
});
457457
458-
// Auto-resize: report content height to host
458+
// Auto-resize: report content height to host.
459+
// Temporarily collapse the container so viewport-relative children (100vh, 100%)
460+
// don't inflate the measurement — this gives us intrinsic content height only.
459461
function reportHeight() {
460462
var content = document.getElementById('content');
461-
var h = content ? content.offsetHeight : document.documentElement.scrollHeight;
463+
if (!content) return;
464+
content.style.height = '0';
465+
content.style.overflow = 'hidden';
466+
var h = content.scrollHeight;
467+
content.style.height = '';
468+
content.style.overflow = '';
462469
window.parent.postMessage({ type: 'widget-resize', height: h }, '*');
463470
}
464471
var ro = new ResizeObserver(reportHeight);
@@ -573,7 +580,7 @@ export function WidgetRenderer({ title, description, html }: WidgetRendererProps
573580
e.data?.type === "widget-resize" &&
574581
typeof e.data.height === "number"
575582
) {
576-
setHeight(Math.max(50, Math.min(e.data.height + 8, 4000)));
583+
setHeight(Math.max(50, Math.min(e.data.height, 4000)));
577584
}
578585
}, []);
579586

apps/app/src/hooks/use-example-suggestions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useConfigureSuggestions } from "@copilotkit/react-core/v2";
33
export const useExampleSuggestions = () => {
44
useConfigureSuggestions({
55
suggestions: [
6-
{ title: "Visualize a binary search", message: "Visualize how binary search works on a sorted list. Step by step." },
6+
{ title: "Visualize a car axle", message: "Visualize how a car axle works" },
77
{ title: "Compare BFS vs DFS", message: "I want to understand the difference between BFS and DFS. Create an interactive comparison on a node graph." },
88
{ title: "Cool 3D sphere", message: "Create a 3D animation of a sphere turning into an icosahedron when the mouse is on it and back to a sphere when it's not on the icosahedron, make it cool." },
99
],

0 commit comments

Comments
 (0)