make all 4 type reports scroll in the same way

This commit is contained in:
Yinyin Liu 2026-03-31 19:56:49 +02:00
parent a8ee946d02
commit 88b5591066
1 changed files with 13 additions and 1 deletions

View File

@ -152,12 +152,22 @@ function ReportHtmlFrame({ html }: { html: string }) {
const iframe = iframeRef.current; const iframe = iframeRef.current;
if (!iframe) return; if (!iframe) return;
let resizeObserver: ResizeObserver | null = null;
const updateHeight = () => { const updateHeight = () => {
try { try {
const doc = iframe.contentDocument || iframe.contentWindow?.document; const doc = iframe.contentDocument || iframe.contentWindow?.document;
if (doc?.body) { if (doc?.body) {
const newHeight = doc.body.scrollHeight + 20; const newHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight) + 40;
if (newHeight > 50) setHeight(newHeight); if (newHeight > 50) setHeight(newHeight);
if (!resizeObserver) {
resizeObserver = new ResizeObserver(() => {
const h = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight) + 40;
if (h > 50) setHeight(h);
});
resizeObserver.observe(doc.body);
}
} }
} catch { /* cross-origin safety */ } } catch { /* cross-origin safety */ }
}; };
@ -168,6 +178,7 @@ function ReportHtmlFrame({ html }: { html: string }) {
return () => { return () => {
iframe.removeEventListener('load', updateHeight); iframe.removeEventListener('load', updateHeight);
timers.forEach(clearTimeout); timers.forEach(clearTimeout);
resizeObserver?.disconnect();
}; };
}, [html]); }, [html]);
@ -175,6 +186,7 @@ function ReportHtmlFrame({ html }: { html: string }) {
<iframe <iframe
ref={iframeRef} ref={iframeRef}
srcDoc={html} srcDoc={html}
scrolling="no"
style={{ style={{
width: '100%', width: '100%',
height, height,