fix(web): the sidebar no longer keeps old renders alive #19852
main fromrefs/pull/19852/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubThe desktop app's main window got slower the longer it stayed open. Its renderer grew about 50–70 MB per hour, from 0.65 GB to over 2 GB in a day. Heap snapshots showed the Sidebar keeping hundreds of its old renders alive. Each one held that render's server configs, so the provider skill lists alone were copied 8,000–22,000 times (about 240 MB).
The cause: several Sidebar useCallback handlers change at different times. One follows serverConfigs, another projectByKey, and so on. A memoized handler keeps the render scope it was created in, and V8 shares that scope with every closure from the same render. So each handler held an older scope, which held older copies of the other handlers, and the chain grew with every update.
The fix gives those six event handlers a fixed identity with a small useStableCallback hook, so they no longer hold old renders. scratchMachineLabelFor is called during render, so it becomes a plain function instead.
How it was checked, in a dev server on a copy of real data, using headless Chromium heap snapshots after 20 rounds of settings, project and thread pin updates:
| Sidebar closures before | after | |
|---|---|---|
main | 567 | 753 (7 handlers +1–2 per update) |
| this PR | 559 | 567 (none grow) |
The thread menu, Project settings, pin/unpin and drag-to-settle still work in the browser.
Reviewed with sol-loop: 1 round with GPT-6.1 Sol on high. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code via T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
Approvability#
Verdict: Approved at
e5f3b21Macroscope's review found this PR approvable — This is a focused Sidebar memory-retention fix with a small stable-callback utility and a targeted test. Existing interactions remain intact while long-lived renders are no longer retained through changing memoized handlers.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
ae7b23da-4829-4b5a-9c41-7e0cf03d14a5
📥 Commits
-
Reviewing files that changed from the base of the PR and between 339179f50a84dc599cce373dbb48f172f182f44e and e5f3b2142312bf9438b694e2878fbdf25a112241.
📒 Files selected for processing: 3
-
apps/web/src/components/Sidebar.tsxapps/web/src/hooks/useStableCallback.test.tsxapps/web/src/hooks/useStableCallback.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
Adds and tests
useStableCallback, which keeps a callback’s identity stable while calling the latest function. Updates several Sidebar handlers to use the hook and convertsscratchMachineLabelForto a plain function.Changes: Stable callback hook and Sidebar adoption
Layer / File(s) Summary Add and test useStableCallback
apps/web/src/hooks/useStableCallback.ts,apps/web/src/hooks/useStableCallback.test.tsxAdds a hook that returns a stable-identity callback and updates the function it calls after a layout effect. The test checks callback identity and that an earlier captured callback returns the latest label. Apply stable callbacks in Sidebar
apps/web/src/components/Sidebar.tsxUses useStableCallbackfor project settings, action sweep, and context-menu handlers. ChangesscratchMachineLabelForto a plain function; its checks remain unchanged.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
e5f3b-
The change appears mergeable after normal checks; no actionable risk was established.
Pre-merge checks:
4-
Passed checks: 4 passed-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title is concise, uses the conventional commit format, and clearly describes the Sidebar memory-retention fix. Description check The description clearly explains the memory-growth problem, the useStableCallback fix, and focused verification results. It does not provide a separate scope-and-approval section or UI screenshots, bu…
-
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 4.9 KiB 5.0 KiB +23 B (+0.5%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB +23 B (+1.9%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.8 KiB 20.9 KiB +41 B (+0.2%) 29.3 KiB ✅ Codex Live turn messages 1 2 +1 (+100.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB −7 B (−0.1%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB −7 B (−0.6%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
339179f· PR result:e5f3b21· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes