From dbfc657652b98a7e11bb047d213a965b462a1b93 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Sun, 11 May 2025 10:52:45 -0700 Subject: [PATCH] feat: use post messaging to transmit route changes --- src/components/IFrame/iFrameHelper.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/components/IFrame/iFrameHelper.tsx b/src/components/IFrame/iFrameHelper.tsx index 84fdbb71c..c597425bd 100644 --- a/src/components/IFrame/iFrameHelper.tsx +++ b/src/components/IFrame/iFrameHelper.tsx @@ -1,10 +1,14 @@ import { useEffect } from "react"; +import { useLocation } from "@docusaurus/router"; function isInIframe() { return window.self !== window.top; } export default function IframeModeProvider() { + const location = useLocation(); + + // Apply iframe styling when inside an iframe useEffect(() => { function applyIframeMode() { if (isInIframe()) { @@ -17,5 +21,19 @@ export default function IframeModeProvider() { applyIframeMode(); }, []); + // Send navigation events to parent window + useEffect(() => { + if (isInIframe()) { + // Send the current location to the parent window + window.parent.postMessage({ + type: 'unraid-docs-navigation', + pathname: location.pathname, + search: location.search, + hash: location.hash, + url: window.location.href, + }, '*'); + } + }, [location]); + return null; }