Repository navigation
Virtualize the CSV preview rows and remote path browser entries - #2163
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
CsvFilePreviewmapped its whole 500x100 parse window into<tr><td><span>(50,000td, ~101k elements in the table, a 2-8 s main-thread block and +33 MB heap, per the report).RemotePathBrowsermapped everyreaddirentry into an<li>inside itsh-56box (5,000 rows / 20,000 elements for a 5,000-file folder) because the daemon listing has no cap. The third surface, the prompt-bannerWorkspaceChangesList, 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 withuseVirtualizer(the patternDiffFilesPanelalready 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 bymeasureElement. 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 aulsized 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 noscrollMarginmeasurement is needed (documented in the code).host.browse_directoryresult shape and need aHOST_DAEMON_PROTOCOL_VERSIONbump, so it is left out of this focused change.How you verified
New tests (jsdom, with
offsetHeightmocked 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,000tdand 14-59 rows, the first row is visible and the last is not; scrolling the box to the bottom mountsr499c0, unmountsr0c0, 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-59li; scrolling to the bottom mountsfile_04999and unmountsfile_00000.Fail before (source files checked out from
origin/main, tests from this branch):Pass after, from the committed tree (
git status --porcelainempty):Manual check on my own dev instance (headless Chromium 1400x900, fixture from the report: 600x120
data/big.csvplus 5,000 untracked files):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 cellr499c0, sticky header still at the top of the box. Scrolled to (6000, 5000): rows 198-240 mounted, sticky#gutter still at the left edge.li, 20,001 nodes in the box): after, 19li, 77 nodes in the box, 108 ms; scrolled to the bottom showsfile_04982-file_04999.Fixes #1615
Independent verification
Checked out
bb/fix-1615-bounded-listsatbf3a653a2(one commit overorigin/main, which is an ancestor; GitHub reports MERGEABLE/CLEAN) in a separate worktree with its own dev instance.Commands:
Fail before (PR tests against
origin/mainsources):Pass after (PR sources restored,
git status --porcelainempty):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.csvcommitted plus 5,000 untracked files, one "Reply only with ok." codex turn to provision the workspace):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 cellr499c0, 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 measuredtd: 50000,tableNodes: 101306, 3.2 s on main. No longer reproduces.li, 77 nodes in the 224 px box (report on main: 5,000li, 20,001 nodes),ulheight 139,981 px. Scrolled to the bottom: 18limounted,file_04991-file_04999visible. Scrolled to the middle:file_02500-file_02508visible with the viewport fully covered. With the "New folder" form open above the list, top and bottom still showfile_00000andfile_04999with no gap. No longer reproduces.WorkspaceChangesList) confirmed already bounded onorigin/main:WORKSPACE_CHANGES_LIST_MAX_ROWS = 200andAnimatedBodymounts 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):
RemotePathBrowserdoes not passscrollMargin, so the virtualizer treats the list as starting at scroll offset 0 while the box'spy-1padding 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 needscrollMargin.tdinstead of 50k. Text selection for "Add to chat" spans only mounted rows, the same limitation the virtualized code view already has.