Repository navigation
fix(bots): attach the bot sidebar virtualizer when the list and rows mount together - #51470
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
…mount together Closing the sidebar unmounts the Bots section, so reopening it mounts the list and its virtual rows in one commit. React attaches the list's ref after the rows' layout effects, so the virtualizer found no scroll element, kept its one-row initialRect and drew that row plus the overscan of 6. With every row at the 48px estimate nothing re-rendered it until another update, such as a bot click. A reveal on that first commit also did nothing, since the rows' scroller was never registered. Find the list from the rows' own element, which is in the DOM by then, instead of from the list's ref. The fixture adds the reopen case. Fixes stablyai#51464 Co-Authored-By: Claude Opus 5.5 <[email protected]>
9f0576f to
e710147
Compare
ELI5
After you closed and reopened the sidebar, the Bots list sometimes drew only the first few bots and left the rest of the space blank until you clicked something. The list tried to measure its container before the container was hooked up, decided it was one row tall, and never checked again. Now the list finds its container by itself, so every bot that fits is drawn right away.
What Changed
Before: Reopening the sidebar drew only Bot 0 to Bot 6 in the Bots section and left the rest blank. Clicking a bot made the missing rows appear. Revealing a row (rename or a search pick) right after reopening did not scroll to it.
After: Every row that fits is drawn as soon as the sidebar opens, and reveals work on the first commit.
Mechanism:
rowsMountedfollowssidebarOpen, so reopening (and the first lazy mount when bots are already loaded) mounts the list<div>andBotSidebarVirtualRowsin one commit. React attaches a parent host's ref only after its children's layout effects run, so when TanStack's_willUpdatelayout effect readgetScrollElement()(listRef.current), it gotnull. The virtualizer had no scroll element and noResizeObserver, kept its 48pxinitialRect, and drew 1 row plusoverscan: 6. Rows measured exactly the 48px estimate, soresizeItemsaw no change and nothing re-rendered. ThebotSidebarVirtualScrollersregistration effect also sawnulland never re-ran, so reveal had no scroller.BotSidebarVirtualRowsputs a ref on its own rows wrapper and finds the list withclosest('[data-bot-sidebar-list]'). A component's own host refs are attached before its layout effects, and the wrapper is already inside the list, so the scroller is found on the first commit. This lookup feeds bothgetScrollElementand the scroller registration.listRefprop is removed.SidebarBotsSectionstops passing it (it still useslistReffor its own layout effects, which run after its ref attaches).mountedWithListcase that mounts the list and rows in one commit. The existing fixture mounts rows one commit after the list, which is why it never caught this.Why
Keeping the ref and forcing a second render once it attaches (or moving the list element into state) would add a render on every mount and track the same element in two places. Looking the list up from the rows' own DOM adds no render, and
[data-bot-sidebar-list]is already howreveal-bot-sidebar-row.tsanduse-bot-search-viewport.tsfind this list.Linked Issue
Fixes #51464
Visual Proof
Component fixture rendered in headless Chromium, list and rows mounted in one commit (400px list, 48px rows).
Before: 7 rows, blank below, reveal does nothing. After: list full, reveal of Bot 150 scrolls there and focuses it.
New
mountedWithListfixture on this PR (all 9 visible rows drawn):Testing
Reproduced with the
mountedWithListfixture (pnpm fixtures:shot bots/BotSidebarVirtualRows): main draws Bot 0 to Bot 6 and "Show list and reveal Bot 9" leaves scrollTop at 0; this PR fills the list and reveal scrolls to Bot 9 (scrollTop 80) and focuses it.N=200 one-commit mount: main 7 rows and reveal of Bot 150 does nothing; this PR 15 rows, reveal sets scrollTop 7200 and focuses "Bot 150", and scrolling renders new rows.
Instrumenting the real
SidebarBotsSectionon main confirmed the first commit on reopen sees a nulllistRef.growingRow,revealAfterHiddenShrinkand the other regression fixture shots are byte-identical between main and this PR.vitestoncomponents/bots/,lib/list-interaction/andsidebar/worktree-list/viewport/: 66 files, 345 tests pass.oxlint, oxfmt, anti-slop oxlint, native code-quality oxlint, ast-grep and the changed-code quality gate: 0 findings.
Platform: macOS, headless Chromium via the component fixture. Pure DOM change, nothing platform-specific.
I manually tested these changes locally (component fixture in headless Chromium)
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
No unit test added: this is UI rendering behavior, which AGENTS.md asks to verify by running it. The
mountedWithListfixture keeps the repro.Performance
None measurable. Renderer only, on the Bots section mount/reopen path:
getScrollElementdoes oneclosest()walk (about 40 ns, vs about 3 ns for a ref read) per virtualizer update, not per row.renderEntrycalls, the same as main's healthy path (rows mounting after the list). N=2000 gives the same counts, so the work does not grow with the number of bots.Risk
The riskiest part is the scroller lookup: if the rows were ever rendered outside a
[data-bot-sidebar-list]element, the virtualizer would have no scroller and fall back to a one-row window. The only callers (SidebarBotsSectionand its fixture) render it directly inside that element, which reveal and search already rely on. Renderer only, no saved data, no SSH or paired-phone surface. Back out with a plain revert.Level: Low
Review
closest()per virtualizer update.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Original fix by @nkmryu in #51470
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)