mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-01 01:52:42 +03:00
fix: infinite reloading (#2405)
This commit is contained in:
parent
38305cd984
commit
2629d39501
@ -129,6 +129,15 @@ export const AllWorkspaceContext = ({
|
|||||||
return <>{children}</>;
|
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 = ({
|
export const CurrentWorkspaceContext = ({
|
||||||
children,
|
children,
|
||||||
}: PropsWithChildren): ReactElement => {
|
}: PropsWithChildren): ReactElement => {
|
||||||
@ -137,12 +146,15 @@ export const CurrentWorkspaceContext = ({
|
|||||||
const exist = metadata.find(m => m.id === workspaceId);
|
const exist = metadata.find(m => m.id === workspaceId);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const push = router.push;
|
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(() => {
|
useEffect(() => {
|
||||||
const id = setTimeout(() => {
|
const id = setTimeout(() => {
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
void push('/');
|
void push('/');
|
||||||
|
globalThis.HALTING_PROBLEM_TIMEOUT <<= 1;
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, globalThis.HALTING_PROBLEM_TIMEOUT);
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(id);
|
clearTimeout(id);
|
||||||
};
|
};
|
||||||
|
@ -28,11 +28,7 @@ export const rootWorkspacesMetadataAtom = atomWithStorage<
|
|||||||
);
|
);
|
||||||
|
|
||||||
// two more atoms to store the current workspace and page
|
// two more atoms to store the current workspace and page
|
||||||
export const rootCurrentWorkspaceIdAtom = atomWithStorage<string | null>(
|
export const rootCurrentWorkspaceIdAtom = atom<string | null>(null);
|
||||||
'root-current-workspace-id',
|
|
||||||
null,
|
|
||||||
createJSONStorage(() => sessionStorage)
|
|
||||||
);
|
|
||||||
|
|
||||||
rootCurrentWorkspaceIdAtom.onMount = set => {
|
rootCurrentWorkspaceIdAtom.onMount = set => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
@ -52,11 +48,7 @@ rootCurrentWorkspaceIdAtom.onMount = set => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const rootCurrentPageIdAtom = atomWithStorage<string | null>(
|
export const rootCurrentPageIdAtom = atom<string | null>(null);
|
||||||
'root-current-page-id',
|
|
||||||
null,
|
|
||||||
createJSONStorage(() => sessionStorage)
|
|
||||||
);
|
|
||||||
|
|
||||||
rootCurrentPageIdAtom.onMount = set => {
|
rootCurrentPageIdAtom.onMount = set => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
Loading…
Reference in New Issue
Block a user