🤯 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(error): collapse repeated network-error toasts into one (#17873)
Innei6bf5c49a5f3f
diff --git a/package.json b/package.jsonindex c339acff82a..771d467348e 100644--- a/package.json+++ b/package.json@@ -303,7 +303,7 @@"@lobehub/icons": "^5.11.0","@lobehub/market-sdk": "0.39.2","@lobehub/tts": "^5.1.2",- "@lobehub/ui": "^5.24.0",+ "@lobehub/ui": "^5.27.0","@modelcontextprotocol/sdk": "^1.29.0","@napi-rs/canvas": "^0.1.100","@neondatabase/serverless": "^1.1.0",diff --git a/src/components/Error/remoteServerErrorToast.test.ts b/src/components/Error/remoteServerErrorToast.test.tsindex e01266c33bc..a5993c7027c 100644--- a/src/components/Error/remoteServerErrorToast.test.ts+++ b/src/components/Error/remoteServerErrorToast.test.ts@@ -1,4 +1,4 @@-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { beforeEach, describe, expect, it, vi } from 'vitest';import { remoteServerErrorToast } from './remoteServerErrorToast';@@ -13,34 +13,30 @@ vi.mock('i18next', () => ({}));beforeEach(() => {- vi.useFakeTimers();toastError.mockClear();});-afterEach(() => {- vi.useRealTimers();-});-describe('remoteServerErrorToast', () => {- it('shows the same errorType at most once per interval', () => {+ it('reuses one toast id per errorType so repeats collapse instead of stacking', () => {remoteServerErrorToast('RemoteServerTimeout');remoteServerErrorToast('RemoteServerTimeout');remoteServerErrorToast('RemoteServerTimeout');- expect(toastError).toHaveBeenCalledTimes(1);- expect(toastError).toHaveBeenCalledWith({+ expect(toastError).toHaveBeenCalledTimes(3);+ expect(new Set(toastError.mock.calls.map(([options]) => options.id)).size).toBe(1);+ expect(toastError).toHaveBeenLastCalledWith({+ id: 'remote-server-network-error-RemoteServerTimeout',title: 'translated_response.RemoteServerTimeout',});-- vi.advanceTimersByTime(10_000);- remoteServerErrorToast('RemoteServerTimeout');- expect(toastError).toHaveBeenCalledTimes(2);});- it('debounces per errorType independently', () => {+ it('gives each errorType its own id', () => {remoteServerErrorToast('RemoteServerDNSFailed');remoteServerErrorToast('RemoteServerOffline');- expect(toastError).toHaveBeenCalledTimes(2);+ expect(toastError.mock.calls.map(([options]) => options.id)).toEqual([+ 'remote-server-network-error-RemoteServerDNSFailed',+ 'remote-server-network-error-RemoteServerOffline',+ ]);});});diff --git a/src/components/Error/remoteServerErrorToast.ts b/src/components/Error/remoteServerErrorToast.tsindex 4e9d3861661..9eeaba55a97 100644--- a/src/components/Error/remoteServerErrorToast.ts+++ b/src/components/Error/remoteServerErrorToast.ts@@ -2,14 +2,9 @@ import type { RemoteServerNetworkErrorType } from '@lobechat/types';import { toast } from '@lobehub/ui/base-ui';import { t } from 'i18next';-const MIN_TOAST_INTERVAL = 10_000;-const lastShownAt = new Map<string, number>();-export const remoteServerErrorToast = (errorType: RemoteServerNetworkErrorType) => {- const now = Date.now();- const last = lastShownAt.get(errorType) ?? 0;- if (now - last < MIN_TOAST_INTERVAL) return;- lastShownAt.set(errorType, now);-- toast.error({ title: t(`response.${errorType}`, { ns: 'error' }) });+ toast.error({+ id: `remote-server-network-error-${errorType}`,+ title: t(`response.${errorType}`, { ns: 'error' }),+ });};