{src !== null ? (
<>
-
+
void;
}) {
const theme = useHtmlRenderTheme();
const frameRef = useRef(null);
@@ -102,6 +105,20 @@ export function HtmlRenderDocument(props: {
window.addEventListener("message", openLink);
return () => window.removeEventListener("message", openLink);
}, []);
+ const { onContentHeight } = props;
+ // A page posts its height once per change, so listen from the commit that
+ // inserts the frame; a passive effect could run after a fast page's first post.
+ useLayoutEffect(() => {
+ if (onContentHeight === undefined) return;
+ const resize = (event: MessageEvent) => {
+ const height = readHtmlRenderContentHeight(event.data);
+ if (height !== undefined && event.source === frameRef.current?.contentWindow) {
+ onContentHeight(height);
+ }
+ };
+ window.addEventListener("message", resize);
+ return () => window.removeEventListener("message", resize);
+ }, [onContentHeight]);
return (