|
| 1 | +# Workspace Tab Instance Isolation Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Make each workspace behave like its own tab instance with isolated layout state and isolated panel/view state. |
| 6 | + |
| 7 | +**Architecture:** Introduce workspace-scoped layout buckets for persistent state, keep adapter atoms for the active workspace, and move panel-local state that must restore across workspace switches into workspace-scoped in-memory buckets. Key the workspace root by `workspace.id` so React never reuses one instance across different workspaces. |
| 8 | + |
| 9 | +**Tech Stack:** React 19, Jotai, Vitest, Testing Library |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +### Task 1: Lock the bug with integration tests |
| 14 | + |
| 15 | +**Files:** |
| 16 | +- Modify: `packages/web/src/features/workspace/index.test.tsx` |
| 17 | +- Test: `packages/web/src/features/workspace/index.test.tsx` |
| 18 | + |
| 19 | +- [ ] **Step 1: Write the failing tests** |
| 20 | + |
| 21 | +Add one test that proves the sidebar tab and terminal/sidebar layout state are isolated between `ws-a` and `ws-b`, and another test that proves content search query/results restore when switching back to the original workspace. |
| 22 | + |
| 23 | +- [ ] **Step 2: Run tests to verify they fail** |
| 24 | + |
| 25 | +Run: `pnpm --filter @coder-studio/web exec vitest run src/features/workspace/index.test.tsx -t "workspace-scoped"` |
| 26 | +Expected: FAIL because the current implementation reuses shared workspace UI state. |
| 27 | + |
| 28 | +### Task 2: Implement workspace-scoped layout state |
| 29 | + |
| 30 | +**Files:** |
| 31 | +- Modify: `packages/web/src/features/workspace/atoms/layout.ts` |
| 32 | +- Modify: `packages/web/src/features/workspace/actions/use-workspace-layout-actions.ts` |
| 33 | +- Modify: `packages/web/src/features/workspace/actions/use-workspace-screen-model.ts` |
| 34 | +- Modify: `packages/web/src/features/topbar/index.tsx` |
| 35 | +- Modify: `packages/web/src/features/command-palette/components/command-palette.tsx` |
| 36 | +- Modify: `packages/web/src/features/focus-mode/components/focus-mode.tsx` |
| 37 | + |
| 38 | +- [ ] **Step 1: Add workspaceId-keyed layout state families and active-workspace adapter atoms** |
| 39 | +- [ ] **Step 2: Update layout actions and screen model to read/write the correct workspace bucket** |
| 40 | +- [ ] **Step 3: Update topbar, command palette, and focus mode to operate on the active workspace bucket** |
| 41 | +- [ ] **Step 4: Run the targeted workspace integration test and fix any regressions** |
| 42 | + |
| 43 | +### Task 3: Implement workspace-scoped panel instance state |
| 44 | + |
| 45 | +**Files:** |
| 46 | +- Modify: `packages/web/src/features/workspace/atoms/layout.ts` |
| 47 | +- Modify: `packages/web/src/features/workspace/views/desktop/workspace-desktop-view.tsx` |
| 48 | +- Modify: `packages/web/src/features/workspace/views/shared/search-panel.tsx` |
| 49 | +- Modify: `packages/web/src/features/workspace/views/shared/git-panel.tsx` |
| 50 | +- Modify: `packages/web/src/features/workspace/views/shared/file-tree-panel.tsx` |
| 51 | +- Modify: `packages/web/src/features/workspace/actions/use-workspace-screen-model.ts` |
| 52 | + |
| 53 | +- [ ] **Step 1: Add workspace-scoped state buckets for panel/session state that must restore on tab switch** |
| 54 | +- [ ] **Step 2: Key the workspace root by `workspace.id`** |
| 55 | +- [ ] **Step 3: Move search, git panel, file tree search, and screen model local state into workspace buckets** |
| 56 | +- [ ] **Step 4: Run the targeted search restoration test and keep both tests green** |
| 57 | + |
| 58 | +### Task 4: Verify affected focused tests |
| 59 | + |
| 60 | +**Files:** |
| 61 | +- Test: `packages/web/src/features/workspace/index.test.tsx` |
| 62 | +- Test: `packages/web/src/features/workspace/views/shared/search-panel.test.tsx` |
| 63 | +- Test: `packages/web/src/features/topbar/index.test.tsx` |
| 64 | + |
| 65 | +- [ ] **Step 1: Run the targeted suite** |
| 66 | + |
| 67 | +Run: `pnpm --filter @coder-studio/web exec vitest run src/features/workspace/index.test.tsx src/features/workspace/views/shared/search-panel.test.tsx src/features/topbar/index.test.tsx` |
| 68 | +Expected: PASS |
| 69 | + |
| 70 | +- [ ] **Step 2: Review diff for unintended cross-workspace behavior changes** |
| 71 | + |
| 72 | +Run: `git diff -- packages/web/src/features/workspace packages/web/src/features/topbar` |
| 73 | +Expected: only workspace instance isolation changes |
0 commit comments