Commit 647bc8c 1 parent c2b61d7 commit 647bc8c Copy full SHA for 647bc8c
File tree 2 files changed +9
-7
lines changed
2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -39,15 +39,16 @@ const IframeCommunication = () => {
39
39
const debounceTimeout = useRef ( null ) ;
40
40
41
41
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
48
49
clearTimeout ( debounceTimeout . current ) ;
49
50
debounceTimeout . current = setTimeout ( ( ) => {
50
- sendMessageToParent ( { type : SupportedMessageTypes . PageHeight , height : contentHeight } ) ;
51
+ sendMessageToParent ( { type : SupportedMessageTypes . PageHeight , height : pageHeight } ) ;
51
52
} , 50 ) ;
52
53
}
53
54
} ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import IframeCommunication from '../components/iframeCommunication';
4
4
5
5
export default function MyApp ( { Component, pageProps } ) {
6
6
useEffect ( ( ) => {
7
+ if ( typeof window === 'undefined' ) return ;
7
8
if ( window . self !== window . top ) {
8
9
document . body . classList . add ( "in-iframe" ) ;
9
10
} else {
You can’t perform that action at this time.
0 commit comments