Skip to content

perf(tab-bar): scrolling the tab strip no longer re-renders every tab - #24240

Merged
nwparker merged 5 commits into
stablyai:mainfrom
AmoabaKelvin:fix/tab-strip-scroll-rerenders
Oct 5, 2026
Merged

nwparker merged 5 commits into
stablyai:mainfrom
AmoabaKelvin:fix/tab-strip-scroll-rerenders

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​365 $\color{#cf222e}{\Huge{\mathbf{−}}}$​77 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​288
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​94 $\color{#cf222e}{\Huge{\mathbf{−}}}$​77 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

ELI5

The thin scroll bar under the tabs kept its position in the tab bar's state. Every time it moved a pixel, the whole tab bar and every tab in it redrew. With 50 tabs open, scrolling stuttered. Now the scroll bar moves itself and the tabs stay put.

What Changed

Before: once the strip overflowed, every scroll step (wheel, trackpad, the arrow buttons, dragging the scroll bar) and every frame of a pane resize re-rendered TabBar and every tab in it, three React commits per scroll step. With 50 tabs a smooth scroll dropped frames, and with the CPU slowed 4x it ran at about 12 fps.

After: scrolling and resizing re-render nothing in the tab bar until the strip reaches an edge, where the arrow buttons and edge fades change. The scroll bar looks and behaves the same.

How:

  • TabBar's overflow state keeps only hasOverflow, canScrollStart and canScrollEnd. Those flip at the edges, not every frame.
  • TabStripScrollIndicator works out the thumb's size and position from the strip's scrollLeft, scrollWidth and clientWidth, and writes width and transform straight to the thumb element. It updates on the strip's scroll event, a ResizeObserver on its track, and the resize notification TabBar already gets from its own observers (subscribeToStripResize), because tabs opening, closing or getting longer titles change the strip's width without a scroll event. The thumb has no React style prop, so a hover re-render can't move it back to an old position.
  • Dragging the thumb and clicking the track measure the thumb from the DOM at the moment you press, so the drag math always matches what is drawn.

Why

The thumb position is the only value here that changes every frame, and only the scroll bar draws it. Keeping it in React state made every frame pay for the whole tab bar. Radix ScrollArea moves its thumb the same way, by writing the style directly. That component doesn't fit here, because its viewport wraps the tabs in an extra element, which breaks the sticky active-tab dock.

Other options I looked at:

  • Memoizing the tab components. TabBar and its hooks would still render three times per scroll step, and the tabs get fresh callbacks on every render, so memo would miss. It's still worth doing for agent-status and title updates, and it's listed as a follow-up below.
  • Moving the thumb with a CSS scroll-driven animation (animation-timeline). That runs no JS per frame, but the thumb width still needs JS, the track is a sibling of the strip so it needs timeline-scope, and it can't be unit tested.

The thumb moves with transform and has will-change-transform. Of the three variants I traced (left, transform, and transform with will-change), that one used the least main-thread time, and WorkspaceKanbanAreaSelectionOverlay already moves its overlay the same way.

Linked Issue

Fixes #24012

Visual Proof

N/A for screenshots: the scroll bar looks and moves exactly as before. The change is in how much work each frame does, measured in a hidden Orca window on macOS with 50 terminal tabs (production build). React commits were counted through the DevTools commit hook, and frames and main-thread time come from Chrome traces.

One sweep of the strip main this PR
Wheel scroll: React commits 112 (37 re-render all 51 tabs) 3 to 6 (only at the edges)
Wheel scroll: main-thread time 839 ms about 270 ms
Smooth scroll: frames over 20 ms 15 of 69 0 to 2 of about 140
Smooth scroll with the CPU slowed 4x 16 frames, median 84 ms 111 to 122 frames, median 7 ms
Pane resize over 60 frames: React commits 183 (61 re-render all tabs) 0
Pane resize: main-thread time 1,233 ms about 355 ms

Timings vary by machine, so they are reported here and not asserted in a test.

Testing

  • tab-strip-growth-scroll.test.tsx: the strip does not re-render for a scroll that stays between the edges. Fails on main.

  • TabStripScrollIndicator.test.tsx: the thumb gets its size when overflow appears, follows scrolling, and shrinks when the strip reports a resize without a scroll event. tab-strip-growth-scroll.test.tsx checks that the strip sends that report when a tab opens.

  • tests/e2e/tab-strip-scroll-render-isolation.spec.ts: in the real app, a 20-step wheel scroll across the middle of a long strip may not produce any React commit that re-renders three or more tabs. On main, all 20 steps re-render 61 tabs each. The wheel events are dispatched in the page, because CI's hidden window draws about one frame a second and real wheel input waits a frame per step. The spec also checks the thumb's position after scrolling, after tabs open, and after the pane narrows. A tab switch at the end acts as a control, so the render recorder can't quietly stop seeing renders.

  • TabStripScrollIndicator.test.tsx also pins the invariant the thumb's position depends on: a hover re-render must leave the same thumb element in place with its width and transform untouched.

  • The e2e spec sets its mid-strip start position after the new terminals stop retitling, and re-sets it until it holds. Opening the tabs leaves the strip pinned to its right edge, and the scroll event that releases that pin only lands with the next frame — about a second in CI's hidden window. A retitle inside that window re-pinned the strip to the end, which would have started the wheel sweep at an edge and flipped the edge flags on every step.

  • Tested on macOS. The change is renderer layout code with no platform branches, and SSH and remote worktrees use the same tab bar.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Worth a close look: the layout effect in TabStripScrollIndicator.tsx. The indicator renders nothing until the strip overflows, so the effect is keyed on hasOverflow. It binds to the thumb when overflow appears and rebinds when overflow goes away and comes back.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Renderer-only change. No new strings, settings, wire fields or persisted data, and nothing changes for SSH, mobile or older clients.

Follow-ups, not in this PR:

  • Memoize the tab components so agent-status and title updates stop re-rendering every tab.
  • tests/e2e/tab-strip-active-dock.spec.ts stops adding tabs at 40, which isn't enough to overflow twice in a wide window, so it fails on main there.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Refactors tab strip scroll rendering to reduce re-renders.

The PR appears safe to merge based on the reviewed changes.

Summary

The PR moves scroll-thumb geometry updates out of React state so scrolling and resizing do not re-render every tab. It retains React state for overflow edges and shares the strip’s existing resize notifications with the thumb.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Strip scroll or resize] --> B[Read strip geometry]
  B --> C[Write thumb width and transform]
  A --> D[Check overflow edges]
  D -->|Edge changes| E[Update React controls and fades]
Loading

Reviews (4) · Last reviewed commit: "test(e2e): set the tab strip scroll star..."

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f321921c-31fb-4275-a8a7-97e3af84b48b
📥 Commits

Reviewing files that changed from the base of the PR and between 57ee293e9f74f62de1788def3d425c18b8669848 and 44808e5.

📒 Files selected for processing (8)
  • src/renderer/src/components/tab-bar/TabStripScrollIndicator.test.tsx
  • src/renderer/src/components/tab-bar/TabStripScrollIndicator.tsx
  • src/renderer/src/components/tab-bar/tab-bar-surface.tsx
  • src/renderer/src/components/tab-bar/tab-strip-growth-scroll.test.tsx
  • src/renderer/src/components/tab-bar/tab-strip-overflow-navigation.ts
  • src/renderer/src/components/tab-bar/tab-strip-scroll-metrics.test.ts
  • src/renderer/src/components/tab-bar/tab-strip-scroll-metrics.ts
  • tests/e2e/tab-strip-scroll-render-isolation.spec.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 42a76bbf-fd2f-4334-82cf-7e9fda2a2350

📥 Commits

Reviewing files that changed from the base of the PR and between 9d00b5a26f869d3c980a23a30994d409688161db and 57ee293e9f74f62de1788def3d425c18b8669848.

📒 Files selected for processing (2)
  • src/renderer/src/components/tab-bar/TabStripScrollIndicator.test.tsx
  • src/renderer/src/components/tab-bar/TabStripScrollIndicator.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The tab strip now keeps overflow and scroll-direction flags separate from thumb size and position. The scroll indicator calculates thumb layout from the live scroll container and updates it on scroll and resize events. Tests check thumb tracking, drag positioning, and tab rendering during scroll.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 57ee2

The thumb tracks live scroll dimensions without storing geometry in tab-bar state. No actionable merge-blocking issue is established; merge readiness remains subject to normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 57ee2

The assessed change remains confined to tab-strip presentation, with no demonstrated expansion of privileged access. Subscription cleanup and interrupted dragging have explicit cleanup paths. Unusual element-replacement behavior and broader security coverage remain incompletely established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated effects are confined to tab-strip scrolling and renderer interaction state, including temporary document-body cursor and selection changes during dragging. The assessed paths do not establish increased tenant, credential, service or persistent-data authority.

Trust Boundaries and Controls

  • inferred — The public-entrypoint routing denotes an exported renderer component and a test-local subscription, not a demonstrated remote or privileged entrypoint. The test constructs its own DOM container and listener set; production separately supplies the tab strip's local ref and subscription.

Resilience and Maintainability Implications

  • observed — Dragging registers matching pointer-move, pointer-up and pointer-cancel handlers. Cleanup restores prior body styles and removes those handlers; it is also invoked on disablement, overflow disappearance and unmount, providing explicit release paths for shared renderer interaction state.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR meets the coding requirements in [#24012]. useTabStripOverflowNavigation retains only overflow and edge-scroll state. TabStripScrollIndicator computes thumb layout from the scroll element a…
Out of Scope Changes check ✅ Passed The production changes directly implement the state separation and local thumb updates requested by [#24012]. The test changes verify the related overflow, resize, thumb-tracking, and render-isolation…
Title check ✅ Passed The title clearly and concisely describes the primary change: tab-strip scrolling no longer re-renders every tab.
Description check ✅ Passed The description follows the required template. It explains the change, rationale, linked issue, visual-proof exception, testing, review notes, compatibility considerations, and checklist status.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3cea7338-30a8-4722-b0df-5498db9942f6

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab3c92 and 922fde8e1e0107be1e3fc7d8a5e0d6d5536b387f.

📒 Files selected for processing (8)
  • src/renderer/src/components/tab-bar/TabStripScrollIndicator.test.tsx
  • src/renderer/src/components/tab-bar/TabStripScrollIndicator.tsx
  • src/renderer/src/components/tab-bar/tab-bar-surface.tsx
  • src/renderer/src/components/tab-bar/tab-strip-growth-scroll.test.tsx
  • src/renderer/src/components/tab-bar/tab-strip-overflow-navigation.ts
  • src/renderer/src/components/tab-bar/tab-strip-scroll-metrics.test.ts
  • src/renderer/src/components/tab-bar/tab-strip-scroll-metrics.ts
  • tests/e2e/tab-strip-scroll-render-isolation.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Thumb position leaves React state — TabStripScrollIndicator writes the thumb's width and transform directly to the DOM from the strip's scroll event, a ResizeObserver on the track, and bindTabStripContentResizeObservers, so a scroll or pane resize no longer commits TabBar and every tab.
  • Overflow state trimmed — TabStripScrollMetrics becomes TabStripOverflowState with only hasOverflow / canScrollStart / canScrollEnd; the thumb fractions and their same* comparison leave the scroll path.
  • Thumb math reads the scroll element — computeTabStripThumbLayout(trackWidthPx, el) derives size/offset from the container's scrollWidth / clientWidth / scrollLeft, and the drag and track-click handlers measure the thumb at press time so the drag math matches what is drawn.
  • Tests — reworked unit tests for the new signatures and E2E spec tab-strip-scroll-render-isolation.spec.ts, which records per-commit tab renders through the always-installed __REACT_DEVTOOLS_GLOBAL_HOOK__ and checks the thumb geometry after scroll, tab growth, and a narrowed pane. I ran the three changed unit test files locally; all 36 pass, and the strip-render-count test is a real regression guard (it fails on the per-frame state update this replaces).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run re-reviewed the two commits pushed since the prior Pullfrog review (922fde8 → 77a23e2).

  • Scroll thumb shares the strip's resize observers — TabStripScrollIndicator no longer binds its own bindTabStripContentResizeObservers; the navigation hook exposes subscribeToStripResize and notifies subscribers from its existing content-resize/mutation observer, removing the duplicate set that watched every tab.
  • E2E spec reworked to not wait on frames — tab-strip-scroll-render-isolation.spec.ts polls thumb geometry, dispatches wheel events in-page, and records tab renders through typed Window globals, replacing the Reflect.get calls the anti-slop lint flagged.
  • Coverage for the shared resize path — a nav-hook unit test asserts subscribers fire when a tab opens without a scroll, and the indicator unit test asserts subscribe-on-overflow and unsubscribe-on-unmount.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run re-reviewed the two commits pushed since the prior Pullfrog review (77a23e2 → 9d00b5a). Both are test-only; no production code changed in this delta.

  • Direct-DOM-write invariant pinned — TabStripScrollIndicator.test.tsx now asserts that a hover re-render leaves the same thumb element in place with its width and transform untouched, guarding the contract that keeps the thumb geometry out of React's control.
  • E2E scroll-start setup hardened — tab-strip-scroll-render-isolation.spec.ts sets the mid-strip start position after recording begins, polls until the position holds (the pin-release scroll event only lands with the next frame in CI's hidden window), and discards the edge-flip commit that scroll causes before the wheel sweep, so it can't be mistaken for the scroll under test.

I ran TabStripScrollIndicator.test.tsx locally — 11/11 pass.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@AmoabaKelvin
AmoabaKelvin force-pushed the fix/tab-strip-scroll-rerenders branch from 9d00b5a to 57ee293 Compare October 1, 2026 13:27

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run re-reviewed the branch head 57ee293, which is the previously reviewed PR content rebased onto the current main (3aa2d3a). No production or test code authored by the PR changed in this delta.

  • Rebase onto newer main — the only differences in the tab-strip files since the prior review at 9d00b5a are main's tab-strip scrollbar restyle (track h-[3px] idle / h-[4px] expanded, bg-muted-foreground/15; thumb bg-muted-foreground/60–/80 with bg-foreground/70 on drag) and the matching color test that landed with it. Both came from main and are correctly outside the PR's merge-base diff — diffPath shows them as context, not additions.
  • Prior findings stand — TabStripScrollIndicator.tsx still writes the thumb's width/transform straight to the DOM behind hasOverflow, and tab-strip-overflow-navigation.ts still fans strip-resize notifications through subscribeToStripResize.
  • Verification at HEAD — the three tab-bar unit suites pass (38 tests), oxlint is clean on the six changed files, tc:web is clean, and the new e2e spec has no type errors.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks Kelvin, I reviewed and tested this one.

The approach is right. The tab bar keeps only the edge flags in state, and the scroll bar moves its own thumb, so a scroll in the middle of the strip no longer touches the tabs. I checked it in a hidden window with 71 tabs. A 30-step wheel scroll went from 90 commits (30 of them re-rendering all 71 tabs) to 1 commit with no tab re-renders. A pane resize went from 56 commits and 994 tab re-renders to 2 commits and none. The thumb lands within a fraction of a pixel of where it should after scrolling, resizing and opening tabs.

Thanks for rebasing past #24276. CI is green, and this looks good to me.

AmoabaKelvin and others added 5 commits October 4, 2026 22:42
The thumb moved every scroll and resize frame, re-rendering every tab with it.

Fixes stablyai#24012
The thumb had its own observer on every tab, on top of the tab bar's.
CI's hidden window draws about one frame a second, so real wheel input timed out. Also drops Reflect.get for the anti-slop audit.
…y alone

The thumb's width and transform live outside React, so the element must survive a
hover re-render with its geometry intact.
…ling

Opening the tabs leaves the strip pinned to its end, and the scroll event that
releases that pin only lands with the next frame - about a second in CI's hidden
window. A tab retitling inside that window re-pinned the strip to the end, so the
wheel sweep would start at an edge and every step would flip the edge flags.
@nwparker
nwparker force-pushed the fix/tab-strip-scroll-rerenders branch from 57ee293 to 44808e5 Compare October 5, 2026 05:44

@nwparker nwparker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scroll thumb geometry avoids per-scroll React state while retaining reactive overflow controls. Resize subscriptions, content growth, drag and close cleanup reviewed; 588 tab-bar tests including render-count regressions pass, plus web typecheck and quality gates.

Required PR Checks verify passed on this exact commit: 44808e5.

@nwparker

nwparker commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Pre-merge bot audit on 44808e5: both review threads are resolved and their fixes remain present. The scroll indicator subscribes to the existing navigation observer; its separate observer watches only the indicator track. The E2E test uses checked Window property access instead of Reflect.get. The docstring-coverage suggestion is declined under AGENTS.md's concise, non-obvious-comment policy; comments explain the geometry and observer ownership where needed. Focused tab-bar validation passed 588 tests, and all current CI checks passed.

@nwparker
nwparker merged commit 355e35b into stablyai:main Oct 5, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scrolling the tab strip may re-render every tab on almost every frame

3 participants