🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: preserve boot reload attempts during async reporting (#17270)
Tsuki35cb7c112285
diff --git a/src/components/BootErrorBoundary/index.test.tsx b/src/components/BootErrorBoundary/index.test.tsxindex 1368a113386..5476cfcb180 100644--- a/src/components/BootErrorBoundary/index.test.tsx+++ b/src/components/BootErrorBoundary/index.test.tsx@@ -4,6 +4,12 @@ import { afterEach, describe, expect, it, vi } from 'vitest';import BootErrorBoundary from './index';+const BOOT_RELOAD_SESSION_KEY = 'lobe:boot:hard-reload-attempts';++const ThrowDuringRender = () => {+ throw new Error('initial boot failure');+};+const ThrowAfterMount = () => {const [failed, setFailed] = useState(false);@@ -17,10 +23,54 @@ const ThrowAfterMount = () => {afterEach(() => {cleanup();+ window.sessionStorage.clear();vi.restoreAllMocks();});describe('BootErrorBoundary', () => {+ it('clears reload attempts after a successful boot', () => {+ window.sessionStorage.setItem(BOOT_RELOAD_SESSION_KEY, '1');++ render(+ <BootErrorBoundary>+ <div>ready</div>+ </BootErrorBoundary>,+ );++ expect(window.sessionStorage.getItem(BOOT_RELOAD_SESSION_KEY)).toBeNull();+ });++ it('preserves the reload limit while initial error reporting is pending', async () => {+ vi.spyOn(console, 'error').mockImplementation(() => {});+ const warning = vi.spyOn(console, 'warn').mockImplementation(() => {});+ let resolveReport: (() => void) | undefined;+ const onError = vi.fn(+ () =>+ new Promise<void>((resolve) => {+ resolveReport = resolve;+ }),+ );+ window.sessionStorage.setItem(BOOT_RELOAD_SESSION_KEY, '1');++ render(+ <BootErrorBoundary fallback={<div>boot fallback</div>} maxBootReloads={1} onError={onError}>+ <ThrowDuringRender />+ </BootErrorBoundary>,+ );++ await waitFor(() => expect(onError).toHaveBeenCalledOnce());+ expect(window.sessionStorage.getItem(BOOT_RELOAD_SESSION_KEY)).toBe('1');++ resolveReport?.();+ await waitFor(() =>+ expect(warning).toHaveBeenCalledWith(+ 'BootErrorBoundary reached max reload attempts',+ expect.objectContaining({ attempts: 1, maxReloads: 1 }),+ ),+ );+ expect(window.sessionStorage.getItem(BOOT_RELOAD_SESSION_KEY)).toBe('1');+ });+it('reports errors through the optional callback', async () => {vi.spyOn(console, 'error').mockImplementation(() => {});const onError = vi.fn(async () => {});diff --git a/src/components/BootErrorBoundary/index.tsx b/src/components/BootErrorBoundary/index.tsxindex 59b7386f1cd..71a4e781a6a 100644--- a/src/components/BootErrorBoundary/index.tsx+++ b/src/components/BootErrorBoundary/index.tsx@@ -33,6 +33,9 @@ class BootErrorBoundary extends Component<BootErrorBoundaryProps, BootErrorBoundprivate hasBooted = false;public componentDidMount() {+ // A fallback mount is not a successful boot; preserve the reload budget across reporting.+ if (this.state.hasError) return;+this.hasBooted = true;this.resetReloadAttempts();this.cleanForceReloadMarker();