Skip to content

🤯 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.

🐛 fix(desktop): stop the applied-update toast from reappearing after it auto-dismisses (#23518)

AmAzing-3f09e5846c07
diff --git a/src/features/Electron/updater/UpdateNotification.tsx b/src/features/Electron/updater/UpdateNotification.tsx
index 2b31b65d893..b630ac44fdf 100644
--- a/src/features/Electron/updater/UpdateNotification.tsx
+++ b/src/features/Electron/updater/UpdateNotification.tsx
@@ -25,9 +25,7 @@ import { densityVars } from '@/styles/densityVars';
import { applyCoreUpdate } from './applyCoreUpdate';
import { formatCoreVersion } from './coreVersion';
import { selectUpdateInfo } from './selectUpdateInfo';
-import { useAutoDismiss } from './useAutoDismiss';
-
-const APPLIED_TOAST_DURATION = 3000;
+import { useAppliedNotice } from './useAppliedNotice';
const styles = createStaticStyles(({ css, cssVar }) => ({
installLaterCloseButton: css`
@@ -156,7 +154,13 @@ export const UpdateNotification: React.FC = () => {
'unconfirm' | 'installLater' | 'installNow' | null
>('unconfirm');
const [isInstalling, setIsInstalling] = useState(false);
- const [appliedVersion, setAppliedVersion] = useState<string | null>(null);
+ // The "updated to version" toast only shows when no pending update takes its slot
+ const {
+ appliedVersion,
+ dismiss: dismissAppliedNotice,
+ hoverHandlers: appliedToastHoverHandlers,
+ setAppliedVersion,
+ } = useAppliedNotice(!!updateInfo);
const receivedUpdateEvent = useRef(false);
useEffect(() => {
let active = true;
@@ -179,7 +183,7 @@ export const UpdateNotification: React.FC = () => {
return () => {
active = false;
};
- }, []);
+ }, [setAppliedVersion]);
useWatchBroadcast('coreUpdateApplied', (version) => {
receivedUpdateEvent.current = true;
setAppliedVersion(version);
@@ -194,13 +198,6 @@ export const UpdateNotification: React.FC = () => {
});
const isDevMode = useUserStore((s) => userGeneralSettingsSelectors.config(s).isDevMode);
- // The "updated to version" toast only shows when no pending update takes its slot
- const appliedToastHoverHandlers = useAutoDismiss(
- updateInfo ? null : appliedVersion,
- () => setAppliedVersion(null),
- APPLIED_TOAST_DURATION,
- );
-
useWatchBroadcast('updateReady', (info) => {
receivedUpdateEvent.current = true;
setUpdateInfo((current) => selectUpdateInfo(current, info));
@@ -270,14 +267,7 @@ export const UpdateNotification: React.FC = () => {
<span>
{tElectron('updater.rendererUpdated', { version: formatCoreVersion(appliedVersion) })}
</span>
- <BaseButton
- size={'small'}
- type={'text'}
- onClick={() => {
- setAppliedVersion(null);
- rendererOtaService.dismissAppliedNotice().catch(console.error);
- }}
- >
+ <BaseButton size={'small'} type={'text'} onClick={dismissAppliedNotice}>
{tElectron('updater.ignore')}
</BaseButton>
</div>
diff --git a/src/features/Electron/updater/useAppliedNotice.test.ts b/src/features/Electron/updater/useAppliedNotice.test.ts
new file mode 100644
index 00000000000..d1f79e3c83d
--- /dev/null
+++ b/src/features/Electron/updater/useAppliedNotice.test.ts
@@ -0,0 +1,53 @@
+import { act, renderHook } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { APPLIED_NOTICE_DURATION, useAppliedNotice } from './useAppliedNotice';
+
+const dismissAppliedNotice = vi.hoisted(() => vi.fn(async () => {}));
+
+vi.mock('@/services/electron/rendererOta', () => ({
+ rendererOtaService: { dismissAppliedNotice },
+}));
+
+const VERSION = '2.3.5-canary.1-core.87';
+
+beforeEach(() => {
+ vi.useFakeTimers();
+ dismissAppliedNotice.mockClear();
+});
+
+afterEach(() => {
+ vi.useRealTimers();
+});
+
+describe('useAppliedNotice', () => {
+ it('clears the main-process notice when the toast times out, so a remount does not show it again', () => {
+ const { result } = renderHook(() => useAppliedNotice(false));
+ act(() => result.current.setAppliedVersion(VERSION));
+
+ act(() => vi.advanceTimersByTime(APPLIED_NOTICE_DURATION));
+
+ expect(result.current.appliedVersion).toBeNull();
+ expect(dismissAppliedNotice).toHaveBeenCalledTimes(1);
+ });
+
+ it('clears the main-process notice when ignored', () => {
+ const { result } = renderHook(() => useAppliedNotice(false));
+ act(() => result.current.setAppliedVersion(VERSION));
+
+ act(() => result.current.dismiss());
+
+ expect(result.current.appliedVersion).toBeNull();
+ expect(dismissAppliedNotice).toHaveBeenCalledTimes(1);
+ });
+
+ it('keeps the notice while a pending update holds the toast slot', () => {
+ const { result } = renderHook(() => useAppliedNotice(true));
+ act(() => result.current.setAppliedVersion(VERSION));
+
+ act(() => vi.advanceTimersByTime(APPLIED_NOTICE_DURATION * 2));
+
+ expect(result.current.appliedVersion).toBe(VERSION);
+ expect(dismissAppliedNotice).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/features/Electron/updater/useAppliedNotice.ts b/src/features/Electron/updater/useAppliedNotice.ts
new file mode 100644
index 00000000000..557a7903216
--- /dev/null
+++ b/src/features/Electron/updater/useAppliedNotice.ts
@@ -0,0 +1,30 @@
+import { useState } from 'react';
+
+import { rendererOtaService } from '@/services/electron/rendererOta';
+
+import { useAutoDismiss } from './useAutoDismiss';
+
+export const APPLIED_NOTICE_DURATION = 3000;
+
+/**
+ * State for the "updated to version" toast. The main process keeps the applied
+ * version until told otherwise, so every way the toast closes (timeout or Ignore)
+ * clears it there too; otherwise a remount, such as a workspace switch, shows it again.
+ * `hidden` pauses the countdown while a pending update takes the toast's slot.
+ */
+export const useAppliedNotice = (hidden: boolean) => {
+ const [appliedVersion, setAppliedVersion] = useState<string | null>(null);
+
+ const dismiss = () => {
+ setAppliedVersion(null);
+ rendererOtaService.dismissAppliedNotice().catch(console.error);
+ };
+
+ const hoverHandlers = useAutoDismiss(
+ hidden ? null : appliedVersion,
+ dismiss,
+ APPLIED_NOTICE_DURATION,
+ );
+
+ return { appliedVersion, dismiss, hoverHandlers, setAppliedVersion };
+};