Skip to content

Virtualize the CSV preview rows and remote path browser entries - #2163

Merged
SawyerHood merged 1 commit into
mainfrom
bb/fix-1615-bounded-lists
Aug 21, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/fix-1615-bounded-lists

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

Two of the three surfaces in #1615 still mounted every row of a large array into a small scroll box. A scroll box clips painting, not DOM, so WebKit still styled, laid out and kept every row in memory. CsvFilePreview mapped its whole 500x100 parse window into <tr><td><span> (50,000 td, ~101k elements in the table, a 2-8 s main-thread block and +33 MB heap, per the report). RemotePathBrowser mapped every readdir entry into an <li> inside its h-56 box (5,000 rows / 20,000 elements for a 5,000-file folder) because the daemon listing has no cap. The third surface, the prompt-banner WorkspaceChangesList, was already fixed on main by #1783 (200-row cap and lazy mount of collapsed bodies).

What changed

  • apps/app/src/components/secondary-panel/FilePreview.tsx: the CSV table mounts only the body rows near the viewport with useVirtualizer (the pattern DiffFilesPanel already uses) on the existing scroll container. Spacer <tr>s above and below the mounted window keep the table's natural height, so the scrollbar, the sticky header row and the sticky row-number gutter behave exactly as before. Row height is a fixed 29px estimate (leading-5 + py-1 + border) corrected by measureElement. Columns are not virtualized; a mounted row still has up to 101 cells, so the bound is roughly 35-45 rows x 101 cells instead of 500 x 101.
  • apps/app/src/components/dialogs/RemotePathBrowser.tsx: the entry list mounts only the rows near the viewport, positioned absolutely inside a ul sized to the virtual total. The "new folder" form stays inside the same scroll box above the list; the 10-row overscan covers its height so no scrollMargin measurement is needed (documented in the code).
  • No wire, CLI or protocol change. The daemon still returns the full directory listing and full CSV file; this PR bounds the DOM, which is what the issue and report measured. Capping the listing at the daemon (the report's optional step) would change the host.browse_directory result shape and need a HOST_DAEMON_PROTOCOL_VERSION bump, so it is left out of this focused change.

How you verified

New tests (jsdom, with offsetHeight mocked so the virtualizer has a viewport):

  • FilePreview.test.tsx > "mounts only the CSV rows near the viewport, not the whole 500x100 window": a 600x120 CSV mounts fewer than 6,000 td and 14-59 rows, the first row is visible and the last is not; scrolling the box to the bottom mounts r499c0, unmounts r0c0, and the truncation note still reads "Showing the first 500 rows and 100 columns."
  • RemotePathBrowser.createFolder.test.tsx > "mounts only the entries near the viewport for a huge directory": a 5,000-entry listing mounts 8-59 li; scrolling to the bottom mounts file_04999 and unmounts file_00000.

Fail before (source files checked out from origin/main, tests from this branch):

× mounts only the entries near the viewport for a huge directory
  AssertionError: expected 5000 to be less than 60
× mounts only the CSV rows near the viewport, not the whole 500x100 window
  AssertionError: expected 50000 to be less than 6000

Pass after, from the committed tree (git status --porcelain empty):

pnpm exec turbo run typecheck --filter=@bb/app   ->  Tasks: 3 successful, 3 total
pnpm exec turbo run test --filter=@bb/app --force ->  Tasks: 4 successful, 4 total
                                                    Test Files 409 passed (409), Tests 3158 passed | 3 skipped (3161)

Manual check on my own dev instance (headless Chromium 1400x900, fixture from the report: 600x120 data/big.csv plus 5,000 untracked files):

  • CSV preview (before, from the report at the same viewport: td: 50000, tableNodes: 101306, 3.2 s to table-in-DOM): after, td: 3401, tableNodes: 7176, 34 body rows, 597 ms from Enter to table-in-DOM including the file fetch. Scroll size unchanged at 28,848x14,529 px. Scrolled to the bottom: rows 467-499 mounted, last cell r499c0, sticky header still at the top of the box. Scrolled to (6000, 5000): rows 198-240 mounted, sticky # gutter still at the left edge.
  • Folder browser on the 5,000-file directory (before: 5,000 li, 20,001 nodes in the box): after, 19 li, 77 nodes in the box, 108 ms; scrolled to the bottom shows file_04982-file_04999.

Fixes #1615

AGENT GENERATED: by Claude Opus 5

Independent verification

Checked out bb/fix-1615-bounded-lists at bf3a653a2 (one commit over origin/main, which is an ancestor; GitHub reports MERGEABLE/CLEAN) in a separate worktree with its own dev instance.

Commands:

git fetch origin main && git fetch origin bb/fix-1615-bounded-lists && git checkout -b verify-1615-r1 FETCH_HEAD
git checkout origin/main -- apps/app/src/components/secondary-panel/FilePreview.tsx apps/app/src/components/dialogs/RemotePathBrowser.tsx
(cd apps/app && pnpm exec vitest run --config vitest.config.ts src/components/secondary-panel/FilePreview.test.tsx src/components/dialogs/RemotePathBrowser.createFolder.test.tsx)
git checkout HEAD -- <same two files>   # then the same vitest command again
pnpm exec turbo run typecheck --filter=@bb/app
pnpm exec turbo run test --filter=@bb/app --force

Fail before (PR tests against origin/main sources):

× mounts only the entries near the viewport for a huge directory
  AssertionError: expected 5000 to be less than 60
× mounts only the CSV rows near the viewport, not the whole 500x100 window
  AssertionError: expected 50000 to be less than 6000
Test Files  2 failed (2)   Tests  2 failed | 26 passed (28)

Pass after (PR sources restored, git status --porcelain empty): Test Files 2 passed (2), Tests 28 passed (28). turbo typecheck --filter=@bb/app: Tasks: 3 successful, 3 total. turbo test --filter=@bb/app --force: Tasks: 4 successful, 4 total, Test Files 409 passed (409).

Repro on the fixed branch (own dev instance, headless Chromium 1400x900 via doobie, report fixture: 600x120 data/big.csv committed plus 5,000 untracked files, one "Reply only with ok." codex turn to provision the workspace):

  • CSV preview, after pressing Enter in the secondary-panel file search: td: 3401, th: 135, tableNodes: 7176, 34 body rows (indexes 0-33), 995 ms Enter-to-table; scroll box 505x742, scroll size unchanged at 28,848x14,529, note "Showing the first 500 rows and 100 columns." Scrolled to the bottom: rows 467-499 mounted, last cell r499c0, sticky header still at the top of the box. Scrolled to (6000, 5000): rows 164-206 mounted, sticky row gutter still at the left edge. The report measured td: 50000, tableNodes: 101306, 3.2 s on main. No longer reproduces.
  • Add-project folder browser on the 5,000-file directory: 19 li, 77 nodes in the 224 px box (report on main: 5,000 li, 20,001 nodes), ul height 139,981 px. Scrolled to the bottom: 18 li mounted, file_04991-file_04999 visible. Scrolled to the middle: file_02500-file_02508 visible with the viewport fully covered. With the "New folder" form open above the list, top and bottom still show file_00000 and file_04999 with no gap. No longer reproduces.
  • Third surface in the issue (prompt-banner WorkspaceChangesList) confirmed already bounded on origin/main: WORKSPACE_CHANGES_LIST_MAX_ROWS = 200 and AnimatedBody mounts children only after the first expand. The banner on my instance exposes a single "Changed files: Untracked, 5000 files" button while collapsed.

CI at verification time: all required checks pass (app-1/2/3, server, packages, integration tests; Package Smoke on ubuntu and macos-15; version check). iOS simulator flows and Node compatibility smoke skipped by path filter.

Residual risks (none blocking):

  • RemotePathBrowser does not pass scrollMargin, so the virtualizer treats the list as starting at scroll offset 0 while the box's py-1 padding and the optional "New folder" form (28 px + 4 px margin, plus an error line) sit above it. The 10-row (280 px) overscan absorbs that offset today; a taller element above the list would need scrollMargin.
  • CSV columns are not virtualized: each mounted row still carries up to 101 cells, so a 100-column file mounts ~3.4k td instead of 50k. Text selection for "Add to chat" spans only mounted rows, the same limitation the virtualized code view already has.
  • The daemon still returns unbounded directory listings and the status route still returns every changed file on the wire; capping those needs a protocol bump and is out of scope here.

AGENT GENERATED: by Claude Opus 5

The CSV file preview mounted every row of its 500x100 parse window
(50,000 td, ~150k DOM nodes, a 2-8 s main-thread block) into a scroll
box that shows ~25 rows, and the "Add project" folder browser mounted
one li per directory entry (5,000 rows for a 224px box) because the
daemon listing has no cap. A scroll box clips painting, not DOM, so
WebKit still styled and laid out every row.

Both lists now mount only the rows near the viewport with the
@tanstack/react-virtual pattern DiffFilesPanel already uses. The CSV
table keeps its sticky header and row-number gutter by padding the
tbody with spacer rows; the folder list positions rows absolutely
inside a sized ul.

Fixes #1615

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood marked this pull request as ready for review August 21, 2026 06:47
@SawyerHood
SawyerHood merged commit d9f3f7f into main Aug 21, 2026
13 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-1615-bounded-lists branch August 21, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant