From a7138493947ca5078452bc3b922ec97d371b60f9 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Sun, 8 Mar 2026 18:34:06 +0000 Subject: [PATCH] Post document height to parent when embedded via iframe Adds a ResizeObserver that sends the root element's scrollHeight to the parent window via postMessage when the app is loaded in embed mode. This allows policyengine-app-v2 to dynamically size the iframe to fit the content without scrollbars. --- src/App.tsx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index fc153e2..e123e06 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'; @@ -12,8 +13,27 @@ const isEmbed = params.has('embed'); const country = params.get('country') || 'us'; export default function App() { + const rootRef = useRef(null); + + // When embedded, report document height to parent for seamless iframe sizing + useEffect(() => { + if (!isEmbed || !rootRef.current) { + return; + } + const observer = new ResizeObserver(() => { + if (rootRef.current) { + window.parent.postMessage( + { height: rootRef.current.scrollHeight }, + '*' + ); + } + }); + observer.observe(rootRef.current); + return () => observer.disconnect(); + }, []); + return ( -
+
{!isEmbed && }