Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: infinite reloading #2405

Merged
merged 4 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion apps/web/src/layouts/workspace-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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);
};
Expand Down
12 changes: 2 additions & 10 deletions packages/workspace/src/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ export const rootWorkspacesMetadataAtom = atomWithStorage<
);

// two more atoms to store the current workspace and page
export const rootCurrentWorkspaceIdAtom = atomWithStorage<string | null>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

storage is unnecessary

'root-current-workspace-id',
null,
createJSONStorage(() => sessionStorage)
);
export const rootCurrentWorkspaceIdAtom = atom<string | null>(null);

rootCurrentWorkspaceIdAtom.onMount = set => {
if (typeof window !== 'undefined') {
Expand All @@ -52,11 +48,7 @@ rootCurrentWorkspaceIdAtom.onMount = set => {
}
};

export const rootCurrentPageIdAtom = atomWithStorage<string | null>(
'root-current-page-id',
null,
createJSONStorage(() => sessionStorage)
);
export const rootCurrentPageIdAtom = atom<string | null>(null);

rootCurrentPageIdAtom.onMount = set => {
if (typeof window !== 'undefined') {
Expand Down