From 75f2d43a3f00db1205078fffcd93a52c08dd3866 Mon Sep 17 00:00:00 2001 From: Toru Kobayashi Date: Mon, 11 Sep 2023 01:02:45 +0900 Subject: [PATCH] fix: crash on multiple SWR instances (#126) --- packages/swr-devtools/src/createSWRDevTools.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/swr-devtools/src/createSWRDevTools.ts b/packages/swr-devtools/src/createSWRDevTools.ts index 91a99f7..075f442 100644 --- a/packages/swr-devtools/src/createSWRDevTools.ts +++ b/packages/swr-devtools/src/createSWRDevTools.ts @@ -113,16 +113,16 @@ export const createSWRDevtools = () => { }); } - const swrdevtools: Middleware = (useSWRNext) => (key, fn, config) => { - // use the same React instance with the application - const { useLayoutEffect, useEffect, useRef } = - typeof window !== "undefined" && - // @ts-expect-error - typeof window.__SWR_DEVTOOLS_REACT__ !== "undefined" - ? // @ts-expect-error - window.__SWR_DEVTOOLS_REACT__ - : dummyHooks; + // use the same React instance with the application + const { useLayoutEffect, useEffect, useRef } = + typeof window !== "undefined" && + // @ts-expect-error + typeof window.__SWR_DEVTOOLS_REACT__ !== "undefined" + ? // @ts-expect-error + window.__SWR_DEVTOOLS_REACT__ + : dummyHooks; + const swrdevtools: Middleware = (useSWRNext) => (key, fn, config) => { useLayoutEffect(() => { window.postMessage({ type: "initialized" }, "*"); }, []);