Skip to content

The agent that grows with you

fix(desktop): a Webapp tab opened on a profile its gateway no longer has stays on the gateway's own

emozillabf9f416e5916
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot-webapp-profile.test.tsx b/apps/desktop/src/app/gateway/hooks/use-gateway-boot-webapp-profile.test.tsx
index 968214d1c84..a942af72720 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot-webapp-profile.test.tsx
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot-webapp-profile.test.tsx
@@ -184,3 +184,12 @@ it('a bare tab opens on the saved default the same way, and records it in its ad
// descriptor names none (a reconnect publishes the tab's own socket), so it must name this one.
expect(new URLSearchParams(window.location.search).get('profile')).toBe('research')
})
+
+it("a tab loaded on a profile the gateway no longer has stays on the gateway's own and names it in its address", async () => {
+ await bootWebappTab('/?profile=gone#/')
+
+ expect($activeGatewayProfile.get()).toBe('default')
+ expect(await sentFor('default', 'session.active_list')).toEqual({})
+ // A reload lands on the profile the tab is really on, not on the stale link's.
+ expect(new URLSearchParams(window.location.search).get('profile')).toBe('default')
+})
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
index c9733a9db88..89b13e5b1ae 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
@@ -184,6 +184,16 @@ async function openWebappTabProfile(desktop: Window['hermesDesktop'], primary: s
return
}
+ // A stale link or bookmark can name a profile this gateway no longer has: stay on the gateway's own.
+ const routes = await desktop.getProfileRoutes?.([profile]).catch(() => null)
+
+ if (routes && !routes.some(route => normalizeProfileKey(route.profile) === normalizeProfileKey(profile))) {
+ console.warn(`[gateway] this gateway has no profile "${profile}"; this tab stays on "${primary}"`)
+ await desktop.profile?.remember?.(primary)
+
+ return
+ }
+
try {
await ensureGatewayProfile(profile)
// As a live switch does: the address names the profile the tab is on, so a reload lands here and