Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): the sidebar no longer keeps old renders alive #19852

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/19852/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

The 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 beforeafter
main567753 (7 handlers +1–2 per update)
this PR559567 (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

    2. juliusmarminge added labelsmacroscope-review

    3. Approvability

      Verdict: Approved at e5f3b21

      Macroscope'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).
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.tsx
      • apps/web/src/hooks/useStableCallback.test.tsx
      • apps/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 converts scratchMachineLabelFor to 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.tsx
      Adds 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.tsx
      Uses useStableCallback for project settings, action sweep, and context-menu handlers. Changes scratchMachineLabelFor to 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: Passed 4
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Title checkPassedThe title is concise, uses the conventional commit format, and clearly describes the Sidebar memory-retention fix.
      Description checkPassedThe 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
      Comment `@coderabbitai help` to get the list of available commands.
    5. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire4.9 KiB5.0 KiB+23 B (+0.5%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB+23 B (+1.9%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.8 KiB20.9 KiB+41 B (+0.2%)29.3 KiB✅
      CodexLive turn messages12+1 (+100.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB−7 B (−0.1%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−7 B (−0.6%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 339179f · PR result: e5f3b21 · Source CI: success

      Scenario 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.

Sign in to join this conversation.