Skip to content

Commit 647bc8c

Browse files
committed
try2
1 parent c2b61d7 commit 647bc8c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

components/iframeCommunication.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ const IframeCommunication = () => {
3939
const debounceTimeout = useRef(null);
4040

4141
const sendPageHeight = () => {
42-
const contentHeight = document.body.offsetHeight;
43-
console.log("Actual content height:", contentHeight);
44-
45-
if (Math.abs(contentHeight - lastHeight.current) > 40) {
46-
lastHeight.current = contentHeight;
47-
42+
const pageHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
43+
44+
// Only send if there's a meaningful difference in height
45+
if (Math.abs(pageHeight - lastHeight.current) > 40) {
46+
lastHeight.current = pageHeight;
47+
48+
// Debounce the message to avoid excessive calls
4849
clearTimeout(debounceTimeout.current);
4950
debounceTimeout.current = setTimeout(() => {
50-
sendMessageToParent({ type: SupportedMessageTypes.PageHeight, height: contentHeight });
51+
sendMessageToParent({ type: SupportedMessageTypes.PageHeight, height: pageHeight });
5152
}, 50);
5253
}
5354
};

pages/_app.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import IframeCommunication from '../components/iframeCommunication';
44

55
export default function MyApp({ Component, pageProps }) {
66
useEffect(() => {
7+
if (typeof window === 'undefined') return;
78
if (window.self !== window.top) {
89
document.body.classList.add("in-iframe");
910
} else {

0 commit comments

Comments
 (0)