From 31071c830836901007364965b9492311edb9b099 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Wed, 31 Jul 2024 11:52:40 +0800 Subject: [PATCH] fix(electron): electron cmd+r issue --- .../modules/workbench/view/desktop-adapter.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/frontend/core/src/modules/workbench/view/desktop-adapter.ts b/packages/frontend/core/src/modules/workbench/view/desktop-adapter.ts index 702176ff13..746a8b22b3 100644 --- a/packages/frontend/core/src/modules/workbench/view/desktop-adapter.ts +++ b/packages/frontend/core/src/modules/workbench/view/desktop-adapter.ts @@ -1,5 +1,5 @@ import type { Location } from 'history'; -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; // eslint-disable-next-line @typescript-eslint/no-restricted-imports import { useLocation } from 'react-router-dom'; @@ -21,6 +21,7 @@ export function useBindWorkbenchToDesktopRouter( basename: string ) { const browserLocation = useLocation(); + const firstNavigation = useRef(false); useEffect(() => { const newLocation = browserLocationToViewLocation( browserLocation, @@ -36,8 +37,19 @@ export function useBindWorkbenchToDesktopRouter( ) { return; } - workbench.open(newLocation); + // skipping default location initialization since we will init the views + // using WorkbenchDefaultState + if (firstNavigation.current) { + workbench.open(newLocation); + } }, [basename, browserLocation, workbench]); + + useEffect(() => { + firstNavigation.current = true; + return () => { + firstNavigation.current = false; + }; + }, []); } function browserLocationToViewLocation(