Fix a bug on resize in développeur/iframe page

pull/2262/head
Jérémy Rialland 2022-08-30 15:58:26 +02:00 committed by Jérémy Rialland
parent 4de5060002
commit 18eb4ad22e
2 changed files with 13 additions and 5 deletions

View File

@ -1,11 +1,23 @@
import { useEffect } from 'react'
function isIframe() {
try {
return window.self !== window.top
} catch (e) {
return true
}
}
export function useIframeResizer() {
useEffect(() => {
// The code below communicate with the iframe.js script on a host site
// to automatically resize the iframe when its inner content height
// change.
if (!isIframe()) {
return
}
const minHeight = 700 // Also used in iframe.js
const observer = new ResizeObserver(([entry]) => {
const value = Math.max(minHeight, entry.contentRect.height)

View File

@ -65,11 +65,7 @@ function IntegrationCustomizer() {
window.addEventListener(
'message',
function (evt: MessageEvent<{ kind: string; value: string }>) {
if (
iframeRef.current &&
evt.data.kind === 'resize-height' &&
iframeRef.current.contentDocument?.readyState === 'complete'
) {
if (iframeRef.current && evt.data.kind === 'resize-height') {
iframeRef.current.style.height = evt.data.value + 'px'
}
}