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 cold start from seeding a duplicate tab (#17822)

Innei1fc7c6facff2
diff --git a/src/features/Electron/TabHost/useSeedTabsOnBoot.test.ts b/src/features/Electron/TabHost/useSeedTabsOnBoot.test.ts
index 011159141d6..020b594e655 100644
--- a/src/features/Electron/TabHost/useSeedTabsOnBoot.test.ts
+++ b/src/features/Electron/TabHost/useSeedTabsOnBoot.test.ts
@@ -41,6 +41,26 @@ describe('useSeedTabsOnBoot', () => {
expect(activeUrl()).toBe('/agent/a#msg_2');
});
+ it('restores the persisted session on a cold start carrying the main-process locale param', () => {
+ saveTabPages(PERSONAL_TAB_SCOPE, [{ id: 'a', lastVisited: 1, url: '/agent/a' }], 'a');
+ window.history.replaceState(null, '', '/?lng=zh-CN');
+
+ renderHook(() => useSeedTabsOnBoot());
+
+ expect(useElectronStore.getState().tabs).toHaveLength(1);
+ expect(useElectronStore.getState().activeTabId).toBe('a');
+ });
+
+ it('matches a persisted tab on a deep link whose query also carries the locale param', () => {
+ saveTabPages(PERSONAL_TAB_SCOPE, [{ id: 'a', lastVisited: 1, url: '/agent/a?topic=t1' }], null);
+ window.history.replaceState(null, '', '/agent/a?topic=t1&lng=zh-CN');
+
+ renderHook(() => useSeedTabsOnBoot());
+
+ expect(useElectronStore.getState().tabs).toHaveLength(1);
+ expect(activeUrl()).toBe('/agent/a?topic=t1');
+ });
+
it('activates a persisted tab instead of adding one when the boot url matches', () => {
saveTabPages(PERSONAL_TAB_SCOPE, [{ id: 'a', lastVisited: 1, url: '/agent/a' }], null);
window.history.replaceState(null, '', '/agent/a');
diff --git a/src/features/Electron/TabHost/useSeedTabsOnBoot.ts b/src/features/Electron/TabHost/useSeedTabsOnBoot.ts
index bb99c73ac23..ced9dce8d68 100644
--- a/src/features/Electron/TabHost/useSeedTabsOnBoot.ts
+++ b/src/features/Electron/TabHost/useSeedTabsOnBoot.ts
@@ -6,6 +6,22 @@ import { useElectronStore } from '@/store/electron';
import { resolveBootAction } from './resolveBootAction';
+// The main process appends `lng` to every renderer load (Browser.buildUrlWithLocale)
+// and index.html consumes it before React mounts. It describes the window, not the
+// route, so it must stay out of tab identity — otherwise a plain launch reads as a
+// deep link into `/?lng=…`, matches no persisted tab, and seeds a duplicate one.
+const readBootUrl = (): string => {
+ const { hash, pathname, search } = window.location;
+
+ const params = new URLSearchParams(search);
+ if (!params.has('lng')) return `${pathname}${search}${hash}`;
+
+ params.delete('lng');
+ const query = params.toString();
+
+ return `${pathname}${query ? `?${query}` : ''}${hash}`;
+};
+
export const useSeedTabsOnBoot = () => {
const seededRef = useRef(false);
@@ -13,7 +29,7 @@ export const useSeedTabsOnBoot = () => {
if (seededRef.current) return;
seededRef.current = true;
- const bootUrl = window.location.pathname + window.location.search + window.location.hash;
+ const bootUrl = readBootUrl();
const { loadTabs } = useElectronStore.getState();
loadTabs(bootUrl);