diff --git a/site/source/components/Provider.tsx b/site/source/components/Provider.tsx index a7453d971..0dce9d644 100644 --- a/site/source/components/Provider.tsx +++ b/site/source/components/Provider.tsx @@ -16,6 +16,7 @@ import { H1, H4 } from '@/design-system/typography/heading' import { Link } from '@/design-system/typography/link' import { Body, Intro } from '@/design-system/typography/paragraphs' import { useIframeResizer } from '@/hooks/useIframeResizer' +import { EmbededContextProvider } from '@/hooks/useIsEmbedded' import { Message } from '../design-system' import * as safeLocalStorage from '../storage/safeLocalStorage' @@ -42,31 +43,33 @@ export default function Provider({ useIframeResizer() return ( - - - - {!import.meta.env.SSR && - import.meta.env.MODE === 'production' && - 'serviceWorker' in navigator && - !inIframe() && } - - - - - - - - {children} - - - - - - - - - - + + + + + {!import.meta.env.SSR && + import.meta.env.MODE === 'production' && + 'serviceWorker' in navigator && + !inIframe() && } + + + + + + + + {children} + + + + + + + + + + + ) } diff --git a/site/source/hooks/useIsEmbedded.tsx b/site/source/hooks/useIsEmbedded.tsx index 2754bd0d1..2f02e272a 100644 --- a/site/source/hooks/useIsEmbedded.tsx +++ b/site/source/hooks/useIsEmbedded.tsx @@ -1,13 +1,25 @@ -import { useMatch } from 'react-router-dom' +import { createContext, useContext, useState } from 'react' export function useIsEmbedded(): boolean { - try { - if (useMatch('/iframes/*')) { - return true - } - } catch (e) { - // When useMatch is called outside ReactRouter context, it raise an error. We can safely ignore it. + return useContext(EmbededContext) +} + +const EmbededContext = createContext(false) + +export function EmbededContextProvider({ + children, +}: { + children: React.ReactNode +}) { + const [isEmbedded, setIsEmbedded] = useState(false) + const isIframePath = document.location.pathname.includes('/iframes/') + if (isIframePath && !isEmbedded) { + setIsEmbedded(true) } - return false + return ( + + {children} + + ) }