fix(desktop): per-window router history and a window title that names the workspace

AS
2mo ago
+337-32

The two follow-ups @Kitenite flagged on #5337.

Restored route wasn't org-scoped

The cause turned out to be one step earlier than the symptom. Router history lives in localStorage under a single router-history key, and localStorage is shared by every window of the profile — so all windows read and wrote one history. The last window to navigate decided where every window reopened, which is why a restored window landed on another window's workspace, in another org.

History is now keyed by the window's persisted key. The renderer gets that key synchronously as a process argument (--superset-window-key), re-exposed by the preload, because the router restores from localStorage at module-evaluation time and can't wait on IPC. The unkeyed record stays as the fallback, which is what lets an existing single-window profile keep its history.

Closed windows would otherwise strand a record on a store with one ~10 MB quota for the whole profile, so a boot sweep drops history whose window is no longer in the registry — window.liveKeys exposes that set. The selection rule is a pure function with tests, including that it never deletes the pre-multi-window record.

Same-org windows shared a title

Several windows on one org is a normal way to work (one per project, one per monitor) and they were one identical entry in the macOS Window menu. The title now leads with the workspace the window is on and keeps the org behind it — Workspace — Org, falling back to the org, then the product name. WindowTitle moved inside HostWorkspacesProvider so it reads rows already fanned out for the sidebar instead of issuing its own lookup.

Verification

Typecheck and Biome clean. Full desktop suite: 2739 pass / 27 fail — identical to main's own baseline on this machine, so no new failures. New unit tests for the sweep rule.

Not done here: I left the workspace route's "not found" screen alone. Once each window restores its own route the cross-org landing goes away at the source, and the remaining case — a workspace that was deleted or moved orgs since — is a genuine not-found that shouldn't be redirected away silently.


Summary by cubic

Scopes @tanstack/react-router history per window and gives each window a title naming its workspace, so reopened windows land on the right workspace and macOS Window menu entries are distinguishable. Previously all windows shared one history and identical titles.

Per-window state

  • Main passes --superset-window-key via BrowserWindow additionalArguments; the preload exposes it as App.windowKey and history is stored under router-history:<windowKey>.
  • A one-time handoff moves the pre-multi-window record to the legacy-single-window window so an existing user's route survives the upgrade.
  • TRPC window.liveKeys feeds a best-effort post-boot sweep that deletes router-history:* entries for closed windows; the legacy record is never swept.
  • Only the legacy-single-window window inherits tabsState; other windows start empty to avoid duplicate pane ids replacing another window's BrowserManager mapping.

Window title

  • WindowTitle moved under HostWorkspacesProvider and sets document.title to "Workspace — Org", falling back to org, then the product name. The workspace route match is fuzzy so nested workspace routes keep the workspace in the title.

No migration required; localStorage stays bounded by per-window limits and the sweep.

Summary by CodeRabbit

  • Bug Fixes

    • Restored windows now reopen to their own workspace and organization instead of sharing navigation history.
    • Removed-window history is cleaned up automatically to prevent stale entries.
    • Window titles more accurately identify the active workspace and organization.
    • New windows start with the correct default tab state instead of inheriting another window’s tabs.
  • Improvements

    • Window identity is preserved consistently across the desktop app.
    • Existing single-window history remains supported during upgrades and recovery.