Skip to content

The agent that grows with you

fix(webapp): keep the router's history state when a profile pick rewrites the URL

David Dudok de Wit7aeeb3b13f5e
diff --git a/apps/desktop/src/lib/browser-profile.test.ts b/apps/desktop/src/lib/browser-profile.test.ts
index 3ebe8d21ebd..baaa58f8177 100644
--- a/apps/desktop/src/lib/browser-profile.test.ts
+++ b/apps/desktop/src/lib/browser-profile.test.ts
@@ -64,6 +64,18 @@ it('persists the default separately from the active chat and synchronizes only t
expect(changed).not.toHaveBeenCalled()
})
+it('records a live profile pick in the URL without dropping the router entry state', async () => {
+ const entry = { idx: 3, key: 'entry', usr: { from: 'sidebar' } }
+ window.history.replaceState(entry, '', '/hermes?profile=active#/session-1')
+ expect(installBrowserDesktopBridge()).toBe(true)
+
+ await window.hermesDesktop.profile.remember('work')
+
+ expect(new URLSearchParams(window.location.search).get('profile')).toBe('work')
+ expect(window.location.hash).toBe('#/session-1')
+ expect(window.history.state).toEqual(entry)
+})
+
it('opens the requested profile on this host without carrying another session or spectator flags', async () => {
// A gated host opens the window directly; a launch-link tab hands it a session first.
bootstrap.__HERMES_AUTH_REQUIRED__ = true
diff --git a/apps/desktop/src/lib/browser-profile.ts b/apps/desktop/src/lib/browser-profile.ts
index 2aead968a63..101a407c043 100644
--- a/apps/desktop/src/lib/browser-profile.ts
+++ b/apps/desktop/src/lib/browser-profile.ts
@@ -60,7 +60,8 @@ export function createBrowserProfileBridge({
const selected = profile?.trim() || null
const url = new URL(window.location.href)
setUrlProfile(url, selected)
- window.history.replaceState(null, '', `${url.pathname}${url.search}${url.hash}`)
+ // Keep react-router's entry state (idx/key/usr): only the URL changes.
+ window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`)
return { profile: selected }
}