diff --git a/site/source/hooks/useIframeResizer.ts b/site/source/hooks/useIframeResizer.ts index 6ac74f637..c4ae5436c 100644 --- a/site/source/hooks/useIframeResizer.ts +++ b/site/source/hooks/useIframeResizer.ts @@ -5,9 +5,7 @@ export function useIframeResizer() { // 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 (!window.location.search.includes('iframe')) { - return - } + const minHeight = 700 // Also used in iframe.js const observer = new ResizeObserver(([entry]) => { const value = Math.max(minHeight, entry.contentRect.height) diff --git a/site/source/pages/Iframes/index.tsx b/site/source/pages/Iframes/index.tsx index 438edcccb..14f1c1a37 100644 --- a/site/source/pages/Iframes/index.tsx +++ b/site/source/pages/Iframes/index.tsx @@ -25,7 +25,7 @@ export default function Iframes() { s.iframePath && ( diff --git a/site/source/pages/Simulateurs/EconomieCollaborative/index.tsx b/site/source/pages/Simulateurs/EconomieCollaborative/index.tsx index 974357b5e..3ecacda5b 100644 --- a/site/source/pages/Simulateurs/EconomieCollaborative/index.tsx +++ b/site/source/pages/Simulateurs/EconomieCollaborative/index.tsx @@ -16,7 +16,7 @@ export default function ÉconomieCollaborative() { const iframePath = useSimulatorsData()['économie-collaborative'].iframePath ?? '' const indexPath = useIsEmbedded() - ? `/iframes/${iframePath}` + ? encodeURI(`/iframes/${iframePath}`) : économieCollaborative.index return ( diff --git a/site/source/pages/Simulateurs/Home.tsx b/site/source/pages/Simulateurs/Home.tsx index 4e1aff656..df4e47cde 100644 --- a/site/source/pages/Simulateurs/Home.tsx +++ b/site/source/pages/Simulateurs/Home.tsx @@ -171,7 +171,8 @@ export function SimulateurCard({ } to={{ - pathname: (isIframe && `/iframes/${iframePath ?? ''}`) || path, + pathname: + (isIframe && `/iframes/${encodeURI(iframePath ?? '')}`) || path, }} state={fromGérer ? { fromGérer: true } : { fromSimulateurs: true }} title={ diff --git a/site/source/pages/integration/Iframe.tsx b/site/source/pages/integration/Iframe.tsx index a63d28e97..24f8de9d1 100644 --- a/site/source/pages/integration/Iframe.tsx +++ b/site/source/pages/integration/Iframe.tsx @@ -59,13 +59,17 @@ function IntegrationCustomizer() { '' const iframeRef = useRef(null) - const iframeSrc = useHref(`/iframes/${currentIframePath}?iframe`) + const iframeSrc = useHref(`/iframes/${currentIframePath}`) useEffect(() => { window.addEventListener( 'message', function (evt: MessageEvent<{ kind: string; value: string }>) { - if (iframeRef.current && evt.data.kind === 'resize-height') { + if ( + iframeRef.current && + evt.data.kind === 'resize-height' && + iframeRef.current.contentDocument?.readyState === 'complete' + ) { iframeRef.current.style.height = evt.data.value + 'px' } }