Repository navigation
Keep sidebar resize off the app-root style path - #1992
Merged
SawyerHood merged 2 commits intoAug 20, 2026
Merged
Conversation
Resizing the left sidebar wrote --sidebar-width on the app root, set cursor/user-select on body, and mounted the drag-guard overlay before the app root. Each is an inherited-property or sibling change that restyles every element in the document, so a drag cost 50-400 ms per frame in a long thread. The width now flows through a SidebarWidthContext and is written only on the sidebar gap and panel, with --sidebar-width registered non-inherited; the overlay carries the cursor and mounts after its siblings. Co-Authored-By: Claude <[email protected]>
…condary-panel drag Co-Authored-By: Claude <[email protected]>
SawyerHood
deleted the
bb/improve-large-thread-sidebar-resizing-thr_q6rsehnvv7
branch
August 20, 2026 02:54
ymichael
added a commit
that referenced
this pull request
Aug 20, 2026
## What was wrong [`SidebarSplitDivider`](https://github.com/get-bb/bb/blob/6be45053be92f964895038fc374a45e759087479/apps/app/src/components/secondary-panel/SidebarSplitContainer.tsx#L679-L757), introduced by [#1601](#1601), wrote both `cursor` and `user-select` to `document.body` at drag start and cleared them at drag finish. Both properties are inherited, so each write invalidated styles across the full app tree. That repeats the root cause measured in [#1992](#1992), where inherited body/root mutations cost hundreds of milliseconds per recalculation on a roughly 20k-element long-thread DOM. The divider also had no unmount cleanup for its native pointer listeners or temporary flex values. ## What changed - Keep the active split-divider cursor in local `SidebarSplitContainer` state instead of mutating `document.body` or the document root. - Mount the existing `IframeDragGuardOverlay` after the split content, with `col-resize` or `row-resize` for the active divider. This keeps the drag captured across iframe/browser-backed pane content without inserting a guard before a large sibling subtree. - Continue relying on the divider's existing pointer-down `preventDefault()` to prevent text selection, matching #1992. - Cancel the in-flight resize on divider unmount: remove native pointer listeners, release capture when held, clear drag chrome, and restore uncommitted flex values. - Remove the now-unused global body cursor helpers, while preserving the panel-library takeover used by main.tsx. This is an app-only change with no host-daemon protocol or other wire changes. It reuses the existing drag guard and straightforward component state; it does not introduce another split framework or alter the split layout model. ## How you verified The focused regression coverage failed before the production change and passed after it. Before the fix, the new assertions observed `cursor: col-resize; user-select: none` on `body` during pointer-down and a stuck `data-dragging="true"` state after unmount. - `pnpm exec turbo run test --filter=@bb/app --force -- src/components/secondary-panel/SidebarSplitContainer.test.tsx src/components/layout/AppLayout.sidebar-resize.test.tsx` — 2 files, 20 tests passed. - `pnpm exec turbo run build typecheck lint --filter=@bb/app` — build and typecheck passed; lint passed with 0 errors and 156 existing warnings. - `git diff --check` — passed. Coverage proves that split drag does not change body/document-root inline styles, pointer-down is default-prevented, the guard mounts after split content with both row and column cursors, pointer-up/cancel remove it, and unmount cancels the drag and removes its native listeners. ## Relationship to #1992 and #2059 This applies #1992's measured performance fix to the internal right-panel divider path that #1992 did not cover. Draft [#2059](#2059) fixes the separate mirrored split-tree correctness problem. Its current head (`4aca1e08`) still contains both body mutations, so it does not supersede this fix. The changes overlap only in `SidebarSplitContainer.tsx` and its test because #2059 rewrites that component; if #2059 lands first, the rebase should keep its single-tree rendering while retaining this PR's container-local cursor state, final drag guard, and divider cleanup. > AGENT GENERATED: by GPT-5.6-Sol
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
Dragging the left sidebar in a long thread was slow (DevTools profile: 2.2 s of style recalculation, ~50 ms per frame, vs 78 ms of layout). Three things in
AppLayouteach forced a restyle of the whole document:--sidebar-widthon the app root (SidebarProvider). A custom property is inherited, so a change on the root invalidates every descendant, including the timeline. Cost scales with thread size (~20–45 µs per element).body.style.userSelectandbody.style.cursor(both inherited) → two more full restyles each.IframeDragGuardOverlaymounted as a sibling before the app root. Inserting/removing a node invalidates every following sibling's subtree → one more full restyle each.Items 1–2 date from the initial sidebar implementation; item 3 came with the iframe guard (#57). Nothing regressed recently; it only becomes visible in large threads.
What changed
ui/sidebar.tsx: newSidebarWidthContextand awidthprop onSidebarProvider.Sidebarwrites--sidebar-widthdirectly on the two elements that read it (gap and panel), not on the wrapper.ui/theme.css:@property --sidebar-width { inherits: false }, so a change restyles only those two elements.layout/AppLayout.tsx: the live width flows through a non-persistedsidebarLiveWidthAtom; only the bridge andSidebarre-render per frame (flushSynckeeps the browser-view bounds sync measuring the updated DOM). Removed bodycursor/user-select: mousedownpreventDefaultalready blocks selection, and the overlay now carries the resize cursor. The overlay mounts after the app root.lib/iframe-drag-guard.tsx: requiredcursorprop, placement note.ThreadSecondaryPanelmoves its overlay after the panel content for the same reason.How you verified
Repro: dev app with
pnpm seed:perf -- --projects 2 --threads 20 --events 60000, open the 9k-event thread in headless Chromium, scroll to the top until ~20k DOM elements are mounted, run a 60-step scripted drag on the resize handle under a CDP trace.Manual checks in the browser: width tracks the drag, commits to localStorage and survives reload, collapse/expand still works, no text selection during drag, overlay shows
col-resize.Tests (fail before, pass after):
AppLayout.sidebar-resize.test.tsx(drag writes only gap/panel, never root or body; overlay mounts after the root with the cursor),sidebar.test.tsx(width lands on gap/panel, not the wrapper),theme.test.ts(@propertynon-inherited).pnpm exec turbo run typecheck lint --filter=@bb/apppasses; 110 test files / 888 tests pass in the touched areas.