update height when an image is loaded

This commit is contained in:
Pavel Mineev
2022-07-11 12:54:48 -05:00
committed by Umputun
parent 1f96a0e4d3
commit aac6af40cc
+9 -1
View File
@@ -315,6 +315,10 @@ const CopyrightLink = (title: string) => (
</a>
);
function updateIframeHeight() {
postMessageToParent({ height: document.body.offsetHeight });
}
/** Root component connected to redux */
export function ConnectedRoot() {
const intl = useIntl();
@@ -326,9 +330,13 @@ export function ConnectedRoot() {
if (!rootRef.current) {
return;
}
// TODO: throttle updates
const observer = new MutationObserver(() => {
postMessageToParent({ height: document.body.offsetHeight });
updateIframeHeight();
// a hacky way to force iframe height update when new image is rendered and loaded
rootRef.current?.querySelectorAll('img').forEach((img) => img.addEventListener('load', updateIframeHeight));
});
observer.observe(rootRef.current, { attributes: true, childList: true, subtree: true });