Fix a bug on resize in développeur/iframe page
parent
4de5060002
commit
18eb4ad22e
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue