Commit 4921a3e
authored
refactor: move sidebar cache management out of archiveSession() (#578)
## Summary
`archiveSession()` was a shared API helper with sidebar-specific SWR
cache logic baked in, creating two problems:
1. **Split ownership** — session removal was spread across two layers:
the helper updated the SWR cache (first-page sessions) while the
sidebar's `handleSessionArchived` updated local `extraSessions` state
(paginated sessions). You had to trace through both files to understand
how a session disappears.
2. **Hidden side effects** — the session page called `archiveSession()`
and silently got a sidebar SWR cache mutation it didn't ask for,
coupling the helper to one caller's UI state.
**Fix:** Make `archiveSession()` a pure API helper (POST + toast). Each
call site now owns its post-archive state management:
- **Sidebar** (`handleSessionArchived`): optimistic SWR cache removal +
`extraSessions` filter + navigation — all in one callback
- **Session page** (`handleArchive`): triggers SWR revalidation via
`mutate(SIDEBAR_SESSIONS_KEY)` + navigates to `/`
Net result is -31/+13 lines — the code is smaller and each layer has a
single, clear responsibility.
## Test plan
- [x] `npm test -w @open-inspect/web` — 192 tests pass
- [x] `npm run typecheck -w @open-inspect/web` — clean
- [x] `npm run lint -w @open-inspect/web` — clean
- [ ] Manual: archive from sidebar → session disappears instantly
- [ ] Manual: archive from session page → redirects to `/`, session gone
from sidebar
- [ ] Manual: archive fails (e.g., network off) → toast shown, session
stays
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Session archival now consistently removes the archived session from
sidebar and session lists across the app, ensuring the UI reflects the
current state immediately.
* The archive operation's success is now treated as API-confirmed;
UI/cache updates are handled by the surrounding UI logic to ensure
consistent updates.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 323e35e commit 4921a3e
3 files changed
Lines changed: 25 additions & 32 deletions
File tree
- packages/web/src
- app/(app)/session/[id]
- components
- lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
| |||
229 | 233 | | |
230 | 234 | | |
231 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
232 | 244 | | |
233 | 245 | | |
234 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
225 | | - | |
226 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
227 | 234 | | |
228 | 235 | | |
229 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | 2 | | |
9 | 3 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 4 | + | |
31 | 5 | | |
32 | | - | |
| 6 | + | |
| 7 | + | |
33 | 8 | | |
34 | 9 | | |
35 | 10 | | |
| |||
39 | 14 | | |
40 | 15 | | |
41 | 16 | | |
42 | | - | |
43 | 17 | | |
44 | 18 | | |
45 | 19 | | |
| |||
0 commit comments