Skip to content

fix(desktop): reopen a chat on the browser tab the user left it on - #7793

Open
waleedlatif1 wants to merge 2 commits into
stagingfrom
fix/browser-tab-restore-on-chat-switch
Open

fix(desktop): reopen a chat on the browser tab the user left it on#7793
waleedlatif1 wants to merge 2 commits into
stagingfrom
fix/browser-tab-restore-on-chat-switch

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Reopening a chat landed on the last browser tab instead of the one the user left it on. The resource strip treated its own last-tab fallback as a selection and pushed it onto the desktop app, overriding the tab the desktop remembers per chat (which also survives relaunch).
  • The shared desktop-tab hook now switches the native tab only for an explicit selection. When the strip is on its fallback and that fallback is a browser or terminal tab, it adopts the desktop's active tab instead, without claiming the selection for the user so agent activity still behaves the same on chat open.
  • A selected tab that has not landed yet (reload with the tab in the URL) is switched to once the desktop's tab list arrives, instead of never.
  • Chat hydration no longer writes a browser or terminal tab into the URL as a fallback; it still pins the last server-held resource.

Type of Change

  • Bug fix

Testing

  • Added hook tests for reopen-adopts-native-tab (browser + terminal), stale selection, non-tab fallback left alone, and deferred switch on reload; verified each fails without the fix.
  • bun run type-check, bun run lint, bun run check:audits (46 audits), all home-surface tests (67 files) pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

🤖 Generated with Claude Code

https://claude.ai/code/session_0139YonWmiZUnPMTHoH4PtAJ

The resource strip pushed its own last-tab fallback onto the desktop app
whenever a chat opened without an explicit selection, overriding the tab
the desktop remembers the user was on. The shared desktop-tab hook now
switches the native tab only for an explicit selection, adopts the
desktop's active tab when the strip is on its fallback, and defers a
selected tab that has not landed yet until it does. Chat hydration no
longer writes a browser or terminal tab into the URL as a fallback.
@vercel

vercel Bot commented Sep 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 12, 2026 9:50am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The PR should not merge until explicit browser and terminal selections are retried when their asynchronously populated native tabs become available.

Findings

  1. P1 Late tabs skip selection

Summary

  • Distinguishes explicit URL selection from the resource strip’s fallback.
  • Defers passive native-tab adoption until chat history hydration completes.
  • Adjusts active-tab closure to select a neighboring resource before removal.
  • Adds browser and terminal hook coverage for restoration and native-switch behavior.

Diagram

sequenceDiagram
  participant URL as URL selection
  participant History as Chat hydration
  participant Strip as Resource strip
  participant Hook as Desktop-tab hook
  participant Native as Desktop native tabs

  URL->>Strip: Explicit resource parameter
  Native-->>Hook: Tab list and active tab arrive
  History-->>Strip: Stored resources applied
  Strip->>Hook: hydrated + selection/fallback
  alt Explicit selected tab is already live
    Hook->>Native: Switch to selected tab
  else Explicit selected tab arrives later
    Note over Hook,Native: Current implementation does not retry
  else No explicit selection
    Hook->>Strip: Passively restore remembered native tab
  end
Loading

Reviews (2) · Last reviewed commit: "fix(desktop): adopt the remembered tab w..."

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-desktop-tab-resources.ts Outdated
…lection

Review round on the reopen fix.

A late first report of the desktop app's active tab carries the tab it
remembers, not a switch the user made, so it is adopted rather than
claimed and agent activity can still take the view on chat open. A move
away from a tab the desktop was already showing stays the user's own.

Adoption now waits for the chat history to be applied, so the arrival
order of the tab list and the history no longer decides which resource a
chat opens on, and it skips a tab the strip has already dropped, so
closing the shown tab cannot write the closed id back. Closing the shown
tab selects its neighbour the way the desktop app picks the next native
tab, instead of flashing through the strip's last tab.

The two wrapper hooks now share one options type with the strip, and the
adopt rule lives in a single helper.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139YonWmiZUnPMTHoH4PtAJ
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment on lines 194 to +199
useEffect(() => {
if (!activeResourceId || activeResourceId === activeTabIdRef.current) return
if (!tabsRef.current.some((tab) => tab.id === activeResourceId)) return
requestedTabIdRef.current = activeResourceId
switchTabRef.current(activeResourceId, scopeIdRef.current)
}, [activeResourceId])
if (!selectedResourceId || selectedResourceId === activeTabIdRef.current) return
if (!tabsRef.current.some((tab) => tab.id === selectedResourceId)) return
requestedTabIdRef.current = selectedResourceId
switchTabRef.current(selectedResourceId, scopeIdRef.current)
}, [selectedResourceId])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Late tabs skip selection

On reload, an explicitly selected browser or terminal tab can be in the URL before the desktop publishes its native tab list. This effect returns while the selected tab is absent and only reruns when selectedResourceId changes. Because tab-list projection no longer retries the selection, a tab that arrives later is never activated and the chat remains on a different native tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant