diff --git a/apps/web/src/layouts/workspace-layout.tsx b/apps/web/src/layouts/workspace-layout.tsx index c6988a7109412..232ccd8b40939 100644 --- a/apps/web/src/layouts/workspace-layout.tsx +++ b/apps/web/src/layouts/workspace-layout.tsx @@ -129,6 +129,15 @@ export const AllWorkspaceContext = ({ return <>{children}; }; +declare global { + // eslint-disable-next-line no-var + var HALTING_PROBLEM_TIMEOUT: number; +} + +if (globalThis.HALTING_PROBLEM_TIMEOUT === undefined) { + globalThis.HALTING_PROBLEM_TIMEOUT = 1000; +} + export const CurrentWorkspaceContext = ({ children, }: PropsWithChildren): ReactElement => { @@ -137,12 +146,15 @@ export const CurrentWorkspaceContext = ({ const exist = metadata.find(m => m.id === workspaceId); const router = useRouter(); const push = router.push; + // fixme(himself65): this is not a good way to handle this, + // need a better way to check whether this workspace really exist. useEffect(() => { const id = setTimeout(() => { if (!exist) { void push('/'); + globalThis.HALTING_PROBLEM_TIMEOUT <<= 1; } - }, 1000); + }, globalThis.HALTING_PROBLEM_TIMEOUT); return () => { clearTimeout(id); }; diff --git a/packages/workspace/src/atom.ts b/packages/workspace/src/atom.ts index fd5a248b38cb3..70d922451417b 100644 --- a/packages/workspace/src/atom.ts +++ b/packages/workspace/src/atom.ts @@ -28,11 +28,7 @@ export const rootWorkspacesMetadataAtom = atomWithStorage< ); // two more atoms to store the current workspace and page -export const rootCurrentWorkspaceIdAtom = atomWithStorage( - 'root-current-workspace-id', - null, - createJSONStorage(() => sessionStorage) -); +export const rootCurrentWorkspaceIdAtom = atom(null); rootCurrentWorkspaceIdAtom.onMount = set => { if (typeof window !== 'undefined') { @@ -52,11 +48,7 @@ rootCurrentWorkspaceIdAtom.onMount = set => { } }; -export const rootCurrentPageIdAtom = atomWithStorage( - 'root-current-page-id', - null, - createJSONStorage(() => sessionStorage) -); +export const rootCurrentPageIdAtom = atom(null); rootCurrentPageIdAtom.onMount = set => { if (typeof window !== 'undefined') {