Skip to content

Commit 3435157

Browse files
waleedlatif1claude
andcommitted
fix(desktop): show a selected tab that arrives after the tab list
The effect that shows an explicitly selected tab was keyed on the selection alone, so a selection made before the desktop app published its tab list was dropped rather than applied when the tab arrived. It is now keyed on that tab being live as well, which covers the late arrival without a retry ref to arm and disarm. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139YonWmiZUnPMTHoH4PtAJ
1 parent 81e0abf commit 3435157

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/hooks/use-browser-tab-resources.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ describe('useBrowserTabResources', () => {
165165
expect(selectResource).not.toHaveBeenCalled()
166166
})
167167

168+
it('shows a page selected before the pages landed, once it arrives', () => {
169+
render({ selectedResourceId: '2', activeResourceId: '2' })
170+
expect(sendBrowserPanelAction).not.toHaveBeenCalled()
171+
172+
pushTabs(SCOPE, [tab('1', true), tab('2')], '1')
173+
expect(sendBrowserPanelAction).toHaveBeenCalledExactlyOnceWith(
174+
'switch-tab',
175+
{ tabId: '2', claim: false },
176+
SCOPE
177+
)
178+
179+
// The requested switch landing is not a native change to follow.
180+
pushTabs(SCOPE, [tab('1'), tab('2', true)], '2')
181+
expect(selectResource).not.toHaveBeenCalled()
182+
})
183+
168184
it('adopts the native active page on reopen instead of pushing the fallback tab', () => {
169185
const resources: MothershipResource[] = [
170186
{ type: 'browser', id: '1', title: 'Page 1' },

apps/sim/app/workspace/[workspaceId]/home/hooks/use-desktop-tab-resources.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,22 @@ export function useDesktopTabResources({
187187
}
188188
}, [addResource, hasSession, removeResource, resources, scopeId, tabs, type])
189189

190+
/** Whether the selected resource is one of this kind's live tabs. */
191+
const selectedTabIsLive =
192+
selectedResourceId !== null && tabs.some((tab) => tab.id === selectedResourceId)
193+
190194
// Selecting a resource tab shows its native tab. Keyed on the explicit
191-
// selection alone: a native push must not re-assert a selection it just
192-
// moved away from, or the two sides would trade switches forever, and the
193-
// strip's fallback is not a choice to impose on the desktop app.
195+
// selection alone — the strip's fallback is not a choice to impose on the
196+
// desktop app, and a native push must not re-assert a selection it just
197+
// moved away from, or the two sides would trade switches forever — and on
198+
// that tab being live, so a selection made before the desktop app published
199+
// its tab list is shown once the tab arrives rather than dropped.
194200
useEffect(() => {
195-
if (!selectedResourceId || selectedResourceId === activeTabIdRef.current) return
196-
if (!tabsRef.current.some((tab) => tab.id === selectedResourceId)) return
201+
if (!selectedResourceId || !selectedTabIsLive) return
202+
if (selectedResourceId === activeTabIdRef.current) return
197203
requestedTabIdRef.current = selectedResourceId
198204
switchTabRef.current(selectedResourceId, scopeIdRef.current)
199-
}, [selectedResourceId])
205+
}, [selectedResourceId, selectedTabIsLive])
200206

201207
// With no effective selection the strip falls back to a tab of its own
202208
// choosing. The desktop app still shows the tab the user was last on, so the

0 commit comments

Comments
 (0)