From f17aa6d1be35c1a76e81d1e66bd94d5619be8947 Mon Sep 17 00:00:00 2001 From: PavelMakarchuk Date: Tue, 17 Feb 2026 16:08:21 -0500 Subject: [PATCH] Post content height to parent window when embedded Uses ResizeObserver to send scrollHeight via postMessage when the ?embed param is present, enabling the parent iframe to resize dynamically so the footer only appears at the bottom. Closes #2 Co-Authored-By: Claude Opus 4.6 --- src/App.tsx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index fc153e2..98e8102 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,3 +1,4 @@ +import { useEffect, useRef } from 'react'; import StickyNav from './components/layout/StickyNav'; import SectionContainer from './components/layout/SectionContainer'; import Footer from './components/layout/Footer'; @@ -11,9 +12,33 @@ const params = new URLSearchParams(window.location.search); const isEmbed = params.has('embed'); const country = params.get('country') || 'us'; +function usePostHeightToParent(rootRef: React.RefObject) { + useEffect(() => { + if (!isEmbed) return; + + const postHeight = () => { + if (rootRef.current) { + window.parent.postMessage( + { type: 'policyengine-model-height', height: rootRef.current.scrollHeight }, + '*', + ); + } + }; + + const observer = new ResizeObserver(postHeight); + if (rootRef.current) observer.observe(rootRef.current); + postHeight(); + + return () => observer.disconnect(); + }, [rootRef]); +} + export default function App() { + const rootRef = useRef(null); + usePostHeightToParent(rootRef); + return ( -
+
{!isEmbed && }