-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3833a91
commit 6e1716c
Showing
3 changed files
with
33 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useEffect } from 'react'; | ||
|
||
export function IframeResizer() { | ||
useEffect(() => { | ||
// Initial height calculation and message | ||
const sendHeightUpdate = () => { | ||
const contentHeight = document.body.scrollHeight; | ||
window.parent.postMessage({ type: 'iframeHeight', height: contentHeight }, '*'); | ||
}; | ||
sendHeightUpdate(); | ||
|
||
// Set up a MutationObserver to watch for changes in the DOM | ||
const observer = new MutationObserver(() => { | ||
// For simplicity, we'll send an update for any mutation, but you can add more specific checks if needed | ||
sendHeightUpdate(); | ||
}); | ||
|
||
// Start observing the entire body and its descendants for changes to the structure of the DOM | ||
observer.observe(document.body, { attributes: true, childList: true, subtree: true }); | ||
|
||
// Cleanup: Disconnect the observer when the component is unmounted | ||
return () => { | ||
observer.disconnect(); | ||
}; | ||
|
||
}, []); | ||
|
||
return null; | ||
} |