From 12e92b7b1288bfe4155391a98a9cd71540f36279 Mon Sep 17 00:00:00 2001 From: Alexis Jacomy Date: Tue, 30 Jan 2024 17:17:57 +0100 Subject: [PATCH] Fixes e2e tests --- src/core/Initialize.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/Initialize.tsx b/src/core/Initialize.tsx index f5ddd88..46f5e90 100644 --- a/src/core/Initialize.tsx +++ b/src/core/Initialize.tsx @@ -11,7 +11,6 @@ import { useFileActions } from "./context/dataContexts"; import { filtersAtom } from "./filters"; import { parseFiltersState } from "./filters/utils"; import { graphDatasetAtom } from "./graph"; -import { fileStateAtom } from "./graph/files"; import { getEmptyGraphDataset, parseDataset } from "./graph/utils"; import { useModal } from "./modals"; import { useNotifications } from "./notifications"; @@ -22,6 +21,11 @@ import { getEmptySession, parseSession } from "./session/utils"; import { resetCamera } from "./sigma"; import { AuthInit } from "./user/AuthInit"; +// This awful flag helps dealing with the double rendering caused from +// React.StrictMode: +// https://react.dev/reference/react/StrictMode#fixing-bugs-found-by-double-rendering-in-development +let isInitialized = false; + export const Initialize: FC> = ({ children }) => { const { t } = useTranslation(); const { notify } = useNotifications(); @@ -59,6 +63,9 @@ export const Initialize: FC> = ({ children }) => { * - ... */ const initialize = useCallback(async () => { + if (isInitialized) return; + isInitialized = true; + // Load session from local storage sessionAtom.set(() => { const raw = sessionStorage.getItem("session"); @@ -86,8 +93,7 @@ export const Initialize: FC> = ({ children }) => { // If query params has gexf // => try to load the file - const isIdle = fileStateAtom.get().type === "idle"; - if (!graphFound && url.searchParams.has("gexf") && isIdle) { + if (!graphFound && url.searchParams.has("gexf")) { const gexfUrl = url.searchParams.get("gexf") || ""; try { await openRemoteFile({ @@ -128,7 +134,6 @@ export const Initialize: FC> = ({ children }) => { appearanceAtom.set((prev) => appearance || prev); resetCamera({ forceRefresh: true }); - graphFound = true; if (dataset.fullGraph.order > 0) showWelcomeModal = false; } }