Skip to content

Commit

Permalink
fix(core): fix infinite retry when workspace not found
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Nov 5, 2024
1 parent 902635e commit e8676c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 9 additions & 6 deletions packages/frontend/core/src/desktop/pages/workspace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
WorkspacesService,
} from '@toeverything/infra';
import type { ReactElement } from 'react';
import { useEffect, useLayoutEffect, useMemo, useState } from 'react';
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { matchPath, useLocation, useParams } from 'react-router-dom';

import { AffineErrorBoundary } from '../../../components/affine/affine-error-boundary';
Expand Down Expand Up @@ -84,13 +84,16 @@ export const Component = (): ReactElement => {
}
}, [listLoading, meta, workspacesService]);

// if workspace is not found, we should revalidate in interval
// if workspace is not found, we should retry
const retryTimesRef = useRef(3);
useEffect(() => {
if (listLoading === false && meta === undefined) {
const timer = setInterval(
() => workspacesService.list.revalidate(),
5000
);
const timer = setInterval(() => {
if (retryTimesRef.current > 0) {
workspacesService.list.revalidate();
retryTimesRef.current--;
}
}, 5000);
return () => clearInterval(timer);
}
return;
Expand Down
14 changes: 9 additions & 5 deletions packages/frontend/core/src/mobile/pages/workspace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Suspense,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import {
Expand Down Expand Up @@ -113,13 +114,16 @@ export const Component = () => {
}
}, [listLoading, meta, workspacesService]);

// if workspace is not found, we should revalidate in interval
// if workspace is not found, we should retry
const retryTimesRef = useRef(3);
useEffect(() => {
if (listLoading === false && meta === undefined) {
const timer = setInterval(
() => workspacesService.list.revalidate(),
5000
);
const timer = setInterval(() => {
if (retryTimesRef.current > 0) {
workspacesService.list.revalidate();
retryTimesRef.current--;
}
}, 5000);
return () => clearInterval(timer);
}
return;
Expand Down

0 comments on commit e8676c1

Please sign in to comment.