From f533eeb0fc541b7450eac75d8a210ebc6077d272 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 4 Apr 2024 09:16:23 -0700 Subject: [PATCH] add support for react dev tools in the cosmos explorer (#1788) --- src/Main.tsx | 3 +++ src/ReactDevTools.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Main.tsx b/src/Main.tsx index d62f9b45e..c6b79b139 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -1,3 +1,6 @@ +// Import this first, to ensure that the dev tools hook is copied before React is loaded. +import "./ReactDevTools"; + // CSS Dependencies import { initializeIcons, loadTheme } from "@fluentui/react"; import { QuickstartCarousel } from "Explorer/Quickstart/QuickstartCarousel"; diff --git a/src/ReactDevTools.ts b/src/ReactDevTools.ts index 09947f934..2a12d81d5 100644 --- a/src/ReactDevTools.ts +++ b/src/ReactDevTools.ts @@ -1,3 +1,7 @@ if (window.parent !== window) { - (window as any).__REACT_DEVTOOLS_GLOBAL_HOOK__ = (window.parent as any).__REACT_DEVTOOLS_GLOBAL_HOOK__; + try { + (window as any).__REACT_DEVTOOLS_GLOBAL_HOOK__ = (window.parent as any).__REACT_DEVTOOLS_GLOBAL_HOOK__; + } catch { + // No-op. We can throw here if the parent is not the same origin (such as in the Azure portal). + } }