fix(core): fix infinite retry when workspace not found (#8679)

This commit is contained in:
EYHN 2024-11-08 09:34:14 +00:00
parent 14d2214248
commit 73d0e64c20
No known key found for this signature in database
GPG Key ID: 46C9E26A75AB276C
2 changed files with 24 additions and 11 deletions

View File

@ -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';
@ -84,13 +84,19 @@ 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(() => {
retryTimesRef.current = 3; // reset retry times
}, [params.workspaceId]);
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;

View File

@ -12,6 +12,7 @@ import {
Suspense,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import {
@ -113,13 +114,19 @@ 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(() => {
retryTimesRef.current = 3; // reset retry times
}, [params.workspaceId]);
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;