Skip to content

Commit 545baf4

Browse files
authored
fix(ui): prevent duplicate nav sidebar when iframe navigates away from auth pages (#63873)
When a user opens a Security panel (e.g. Users) and clicks the Airflow logo inside the embedded FAB iframe, the iframe navigates to '/' which causes the React SPA to render inside the iframe, including its own Nav sidebar. This produces a duplicate navigation bar alongside the outer app's sidebar. Fix: before calling navigate('/'), set iframe.src = 'about:blank' to immediately clear the iframe content so the inner React app has no chance to render its Nav. A isRedirecting ref guards against the extra onLoad event that setting src to about:blank would otherwise trigger. Closes #63805
1 parent 0b2efb9 commit 545baf4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

airflow-core/src/airflow/ui/src/pages/Security.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* under the License.
1818
*/
1919
import { Box } from "@chakra-ui/react";
20+
import { useRef } from "react";
2021
import { useNavigate, useParams } from "react-router-dom";
2122

2223
import { useAuthLinksServiceGetAuthMenus } from "openapi/queries";
@@ -38,14 +39,25 @@ export const Security = () => {
3839
const link = authLinks?.extra_menu_items.find((mi) => mi.text.toLowerCase().replace(" ", "-") === page);
3940

4041
const navigate = useNavigate();
42+
// Track when we are already redirecting so that setting iframe.src = "about:blank"
43+
// (which fires another onLoad event) does not trigger a second navigate call.
44+
const isRedirecting = useRef(false);
4145

4246
const onLoad = () => {
47+
if (isRedirecting.current) {
48+
return;
49+
}
50+
4351
const iframe: HTMLIFrameElement | null = document.querySelector("#security-iframe");
4452

4553
if (iframe?.contentWindow) {
4654
const base = new URL(document.baseURI).pathname.replace(/\/$/u, ""); // Remove trailing slash if exists
4755

4856
if (!iframe.contentWindow.location.pathname.startsWith(`${base}/auth/`)) {
57+
// Clear the iframe immediately so that the React app does not render its own
58+
// navigation sidebar inside the iframe, which would produce a duplicate nav bar.
59+
isRedirecting.current = true;
60+
iframe.src = "about:blank";
4961
void navigate("/");
5062
}
5163
}

0 commit comments

Comments
 (0)