mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
fix(core): fix infinite retry when workspace not found (#8679)
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
|||||||
WorkspacesService,
|
WorkspacesService,
|
||||||
} from '@toeverything/infra';
|
} from '@toeverything/infra';
|
||||||
import type { ReactElement } from 'react';
|
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 { matchPath, useLocation, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
import { AffineErrorBoundary } from '../../../components/affine/affine-error-boundary';
|
import { AffineErrorBoundary } from '../../../components/affine/affine-error-boundary';
|
||||||
@@ -84,13 +84,19 @@ export const Component = (): ReactElement => {
|
|||||||
}
|
}
|
||||||
}, [listLoading, meta, workspacesService]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
if (listLoading === false && meta === undefined) {
|
if (listLoading === false && meta === undefined) {
|
||||||
const timer = setInterval(
|
const timer = setInterval(() => {
|
||||||
() => workspacesService.list.revalidate(),
|
if (retryTimesRef.current > 0) {
|
||||||
5000
|
workspacesService.list.revalidate();
|
||||||
);
|
retryTimesRef.current--;
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
return () => clearInterval(timer);
|
return () => clearInterval(timer);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
Suspense,
|
Suspense,
|
||||||
useEffect,
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import {
|
import {
|
||||||
@@ -113,13 +114,19 @@ export const Component = () => {
|
|||||||
}
|
}
|
||||||
}, [listLoading, meta, workspacesService]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
if (listLoading === false && meta === undefined) {
|
if (listLoading === false && meta === undefined) {
|
||||||
const timer = setInterval(
|
const timer = setInterval(() => {
|
||||||
() => workspacesService.list.revalidate(),
|
if (retryTimesRef.current > 0) {
|
||||||
5000
|
workspacesService.list.revalidate();
|
||||||
);
|
retryTimesRef.current--;
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
return () => clearInterval(timer);
|
return () => clearInterval(timer);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user