Skip to content

feat: Zed-style overlay scrollbars#509

Merged
backnotprop merged 9 commits intomainfrom
feat/full-transparent-scroll
Apr 7, 2026
Merged

feat: Zed-style overlay scrollbars#509
backnotprop merged 9 commits intomainfrom
feat/full-transparent-scroll

Conversation

@backnotprop
Copy link
Copy Markdown
Owner

Summary

Wide, translucent, full-length overlay scrollbars across plan mode and code review, replacing the 6px WebKit rail that users couldn't reliably click or grab. Click the track to page-animate toward the click, drag the thumb smoothly, no layout shift, Firefox parity, respects prefers-reduced-motion, disappears in print.

Backed by overlayscrollbars-react wrapped in a new <OverlayScrollArea> component. The library handles pointer capture, click-to-jump, hover reveal, auto-hide, RTL, touch, and momentum — we keep native scroll semantics on the viewport element so existing scrollIntoView / scrollTo calls still work.

The marker layer (annotation ticks, diff-hunk ticks, search hits on the track) is deliberately deferred as a downstream feature; this PR is the foundation.

What ships

New

  • packages/ui/components/OverlayScrollArea.tsx — wrapper with a memoized options object, imperative getViewport() handle, onViewportReady callback, forwards all standard HTML props, honors prefers-reduced-motion.
  • packages/ui/hooks/useScrollViewport.ts — React context + hook so descendants can reach the real scrolling element without document.querySelector('main') (which no longer returns the scroll node after wrapping).
  • packages/ui/hooks/useOverlayViewport.ts — canonical ref+state+callback pattern for components that need both imperative scroll access and effect re-runs when the library viewport mounts.

Wrapped scroll containers

Plan mode:

  • Main plan viewer (packages/editor/App.tsx)
  • Annotation panel
  • Sidebar (TOC / Version Browser / Archive)
  • Settings modal
  • Export modal

Code review:

  • File tree
  • Review sidebar (right panel)
  • AI chat tab
  • PR comments timeline
  • PR summary + PR checks dock panels
  • Diff viewer (with containerRef → library viewport plumbing for file-switch reset, annotation scroll, search highlight, search scroll)
  • Live log viewer (with plumbing for follow-tail heuristic + auto-scroll-to-bottom)

Theme

  • New .os-theme-plannotator CSS variable set sourced from existing theme tokens — 10px at rest, 14px on hover, translucent muted-foreground handle, transparent track at rest. Color + width transitions only — deliberately does not reintroduce transform/opacity in global transitions, preserving the abc952f scroll-jank fix.
  • Firefox scrollbar-width: thin + scrollbar-color fallback for unwrapped surfaces.
  • print.css hides .os-scrollbar during print.

Not touched (intentionally native): max-h-24 / max-h-48 inline scrollers (annotation original-text preview, agent prompt disclosure boxes, theme grid), the AskAI suggestion dropdown, the PRCommentsTab horizontal author filter, dockview's own tab-strip scrollers. A 14px overlay scrollbar would dominate these.

Related issues and PRs

Architectural notes

  • ClickScrollPlugin must be registered explicitly. In overlayscrollbars v2, clickScroll: 'instant' works out of the box, but clickScroll: true (page-animate toward the click — the "like a website" behavior) silently no-ops unless OverlayScrollbars.plugin(ClickScrollPlugin) runs at module load. Registered once in OverlayScrollArea.tsx.
  • Dockview deferral. Dockview's internal tab-strip scrollbars stay native in this PR — they're dockview's own CSS surface, not ours, and the juice isn't worth it. We wrap panel content (DiffViewer, PR panels, AgentJobDetail), not panel hosts.
  • @pierre/diffs split-view sync is unaffected. Verified pre-flight: its ScrollSyncManager attaches scroll listeners to its own internal codeDeletions/codeAdditions elements inside the content, not the outer container we wrap.
  • Bundle cost: ~30kB gzip for overlayscrollbars + the React wrapper. Acceptable given we already ship highlight.js and dockview-react.

Test plan

  • Plan mode: main viewer, annotation panel, sidebar, settings modal, export modal
    • Click track below thumb → page-animates toward click
    • Drag thumb → smooth scroll
    • Hover reveal fades in/out correctly
    • No layout shift when scrollbar appears/disappears
    • ResizeHandle grabs cleanly on both side="left" and side="right" at both 10px rest and 14px hover widths
  • Plan mode scroll behaviors preserved: annotation card → highlight scroll, highlight → annotation card scroll, TOC entry → heading scroll, deny + resubmit diff view
  • Code review: file tree, review sidebar tabs (annotations / AI / agents), PR comments timeline, PR summary panel, PR checks panel, diff viewer, live log viewer
    • File-switch resets diff scroll to top-left
    • Annotation click scrolls diff to highlight
    • Search step-through scrolls each match into view
    • Split-view sync still works; split handle drag still works
    • LiveLogViewer follow-tail auto-scrolls on new content and pauses when user scrolls up
    • AITab auto-scrolls on new messages and jump-to-question works
  • Firefox: every wrapped scroller renders with themed overlay, not native Firefox scrollbars
  • Print: no scrollbars visible
  • Reduced motion (macOS System Settings → Accessibility → Display): no fade, scrollbars always visible
  • Theme switching: scrollbar colors track theme tokens across all 18 themes without flicker

Wide, translucent, full-length overlay scrollbars replacing the 6px
WebKit rail that users couldn't reliably grab. Click the track to
page-animate toward the click, drag the thumb, no layout shift, Firefox
parity.

Wraps plan-mode scroll containers (main viewer, annotation panel,
sidebar, settings, export modal) in a new <OverlayScrollArea> component
backed by overlayscrollbars-react. The library handles pointer capture,
click-to-jump, hover reveal, auto-hide, RTL, touch, momentum, and
cross-browser consistency. ClickScrollPlugin registered explicitly so
`clickScroll: true` actually pages (otherwise it silently no-ops).

Plumbing:

- New ScrollViewportContext + useScrollViewport() hook so descendants
  (TableOfContents, PinpointOverlay, Viewer sticky observer) can reach
  the real scrolling element instead of document.querySelector('main'),
  which no longer returns the scroll node after wrapping.
- New useOverlayViewport() hook — canonical ref+state+callback pattern
  bridging the library viewport into components that need both
  imperative access and effect re-runs when the viewport mounts.
- useActiveSection gains an optional scrollElement arg so its
  IntersectionObserver root re-attaches when the viewport becomes
  available (ref mutations don't retrigger effects).

Theme:

- New .os-theme-plannotator tokens sourced from existing theme CSS
  variables (translucent muted-foreground for handle, transparent track
  at rest). 10px at rest, 14px on hover. Color + width transitions
  only — deliberately does not reintroduce transform/opacity in global
  transitions, preserving the abc952f scroll-jank fix.
- Firefox `scrollbar-width: thin` + `scrollbar-color` fallback for
  unwrapped surfaces (micro-scrollers, future dockview).
- print.css hides .os-scrollbar during print.

ResizeHandle (#354 regression guard):

- `side="right"` touch area retuned from `-right-3 left-0` to
  `-right-3 left-3` to clear the 14px hover scrollbar. Load-bearing
  comment added explicitly warning against simplification because #354
  has already regressed twice.

Intentionally left native: max-h-24 inline scrollers
(EditorAnnotationCard, AgentsTab, ThemeTab), dropdown menus — a 14px
overlay scrollbar would dominate those UI elements.

Fixes #354
Follow-up to #359, #465 (both fixed #354, which kept regressing)
Preserves #253 bidirectional annotation scroll
Preserves #452 file-switch reset (plan mode portion)

For provenance purposes, this commit was AI assisted.
Wrap the trivial code-review scroll containers in <OverlayScrollArea>:
FileTree, ReviewSidebar content area, AITab chat history, PRCommentsTab
timeline, and the ReviewPRSummary / ReviewPRChecks dock panels.

None of these components read scrollTop / scrollHeight / scrollLeft
directly — all descendant queries use containerRef.current.querySelector
and all scroll-to-target calls use element.scrollIntoView, which walks
up to the nearest scrollable ancestor (now the library viewport). No
plumbing changes required.

AITab was originally scoped to Commit B but an audit of its scroll
effects (jump-to-question + auto-scroll-to-bottom) confirmed it only
uses descendant scrollIntoView, so it ships here.

DiffViewer and LiveLogViewer follow in a separate commit — they
programmatically read/write scrollTop and need explicit viewport
plumbing via useOverlayViewport.

For provenance purposes, this commit was AI assisted.
Wrap DiffViewer's main scroll container and LiveLogViewer's log pane in
<OverlayScrollArea>, plumbing containerRef through useOverlayViewport
so imperative scroll reads/writes and IntersectionObserver roots land
on the real library viewport, not the OverlayScrollArea host.

DiffViewer:

- `previousScrollFilePathRef` guard added: the file-switch reset
  (#452) now only advances the tracking ref once the scroll actually
  executed, closing a race where a file switch landing before the
  library viewport attached would leave the ref stale while the
  scrollTo silently no-oped.
- `viewport` added to every effect dep that reads containerRef.current
  (file-switch reset, annotation scroll, search-highlight apply +
  swap, scroll-to-match) so they re-run when the viewport mounts.
  Without this they'd silently no-op on first paint.
- Split-view sync via @pierre/diffs unaffected — its ScrollSyncManager
  attaches scroll listeners to its own internal codeDeletions /
  codeAdditions elements inside the content, not the outer scroller.

LiveLogViewer:

- React onScroll replaced with a native addEventListener('scroll', ...)
  inside a useEffect keyed on `viewport` because React's onScroll
  doesn't bubble across the library's wrapper layers.
- Follow-tail heuristic (`scrollHeight - scrollTop - clientHeight < 40`)
  and the auto-scroll-to-bottom assignment both preserved verbatim —
  only the ref target changed from the raw div to the library viewport.

Preserves #452 file-switch reset
Preserves #253 bidirectional annotation scroll (diff side)

For provenance purposes, this commit was AI assisted.
Two P1 bugs from the review, plus four correctness/cleanup items.

P1: OverlayScrollbars viewport was never delivered to consumers.

handleOsRef was reading osInstance() synchronously from the React ref
callback, but `defer: true` queues the library's initialization for a
later frame — at ref-callback time, the internal instance ref is still
null. With a stable useCallback the ref never re-fires, so
onViewportReady was never called with a real viewport. Every consumer
of useOverlayViewport/useScrollViewport stayed permanently null:
useActiveSection, TableOfContents.handleNavigate, Viewer sticky
detection, PinpointOverlay, DiffViewer file-switch reset, LiveLogViewer
follow-tail — all silently no-ops.

Fix: deliver the viewport via the library's own `events.initialized`
and `events.destroyed` callbacks, which fire exactly when elements are
ready and when they're torn down. `getViewport()` prefers the tracked
viewport ref over the imperative osInstance() path so late callers
still work.

P1: right-side ResizeHandle touch area was 0px wide.

Touch area is an absolute-positioned child of a w-0 parent, so actual
width = parent - left - right. With side='right' I'd set `left-3
-right-3`, which evaluates to `0 - 12 - (-12) = 0`. The annotation
panel resize handle in plan mode and both right handles in code review
had no draggable region. The visible 4px track has no event handlers,
so the only affordance was cursor-style feedback — drag did nothing.

Fix: revert to `left-0 -right-3` (12px wide, entirely right of the
boundary, no left encroachment into the adjacent scrollbar zone —
which was the original correct value before this branch). Rewrote the
comment to explain the geometry trap instead of protecting the value
that broke it.

Additional fixes:

- OverlayScrollArea: prefers-reduced-motion now reactive via
  useSyncExternalStore — OS toggle mid-session propagates to mounted
  instances instead of staying frozen at mount-time snapshot.
- OverlayScrollArea: `ref as never` replaced with a narrow cast to
  `React.RefCallback<OverlayScrollbarsComponentRef<'div'>>` so future
  signature changes get type feedback.
- PinpointOverlay: window resize listener moved above the scroll
  viewport guard so it attaches unconditionally. Scroll listener still
  requires the viewport (correct). Old code always registered resize
  on window; new code was accidentally skipping it when viewport was
  null.
- TableOfContents: `className || default` changed to `className ??
  default`. An explicit empty string from a caller (SidebarContainer
  passing className="" now that it wraps us in an OverlayScrollArea)
  should mean "no container styling", not "use the default". The old
  || operator treated "" as falsy and applied the default, leaving
  dead overflow-y-auto and unintended backdrop-blur on the nav.
- useOverlayViewport: removed redundant double cast and `?? null`
  no-op in the ref setter.

For provenance purposes, this commit was AI assisted.
When <main> is wrapped in OverlayScrollArea, the library adds its own
attribute-selector CSS rules: `[data-overlayscrollbars~="host"]` gets
`overflow: hidden !important` and `[data-overlayscrollbars-viewport]`
gets `overflow-x/y: hidden` (or scroll) with fixed viewport heights.
These beat our existing `main { overflow: visible !important }` print
override on specificity — attribute selectors outrank tag selectors
even when both use `!important`. Result: long plans printed only the
currently-visible viewport instead of flowing across pages.

Fix: add a print-scoped override that targets the library's attribute
selectors directly, setting overflow:visible, height:auto,
max-height:none, and display:block to defeat both the overflow clip
and the flex layout the library applies to host/padding wrappers.

Verified by printing a multi-page plan in the dev server.

For provenance purposes, this commit was AI assisted.
Switch autoHide from 'leave' to 'never'. The previous behavior faded
the scrollbar 800ms after the pointer left the scroll host, which felt
broken in a common interaction pattern: click a TOC entry (pointer in
the sidebar) → trackpad-scroll (pointer still in sidebar) → 800ms idle
→ scrollbar disappears. User had to hover the right edge to bring it
back on every interaction.

Persistent visibility matches the pattern used by every editor-class
technical app (VS Code, Zed, JetBrains, Xcode, Sublime) where the
scrollbar is both a position indicator and a targeting surface for
click-to-jump. Overlay scrollbars cost zero layout space, so "always
visible" has no downside.

Also removes the dead `.os-theme-plannotator .os-scrollbar` selector
from the reduced-motion block. The library applies the theme class
directly to the .os-scrollbar element itself (verified in the library
runtime source, not just CSS), so a descendant selector with a space
matches nothing. The track and handle selectors in the same block
work correctly (they really are descendants) and are preserved.

The component's own prefers-reduced-motion hook and helpers are now
unused (autoHide is unconditionally 'never') and removed. Reduced
motion is still honored for the hover color + width transitions on
track/handle via the CSS @media (prefers-reduced-motion: reduce)
block in theme.css, which the browser evaluates independently.

For provenance purposes, this commit was AI assisted.
…r behavior

The component header still described the old autoHide:'leave' behavior
and implied the reduced-motion branch was in the component itself.
Neither is true after cf137bf. Rewrite the jsdoc to describe the
current behavior: always visible, no fade, reduced-motion handled via
a CSS media query in theme.css rather than a React branch.

For provenance purposes, this commit was AI assisted.
…ines)

When pierre/diffs expanded context lines on a file whose diff previously
fit inside the viewport, the scrollbar stayed hidden until the user
manually scrolled or dragged the split-ratio handle to force a layout
recalculation.

Root cause: OverlayScrollbars' internal content observer doesn't see
the mutation because pierre/diffs renders inside a shadow DOM, and
MutationObserver does not pierce shadow DOM by default. The library's
own host-level size observer doesn't help either — the host (our
<main> / flex-1 container) has a fixed layout size that doesn't
change when content grows.

Fix: track the OverlayScrollbars instance in state and attach a
ResizeObserver to the viewport's first element child in a useEffect.
When the content's layout box grows — which happens even when the
growth originates inside a shadow tree, because layout size
propagates from shadow content to the shadow host — the observer
fires and calls `instance.update(true)` to recompute scrollbar
visibility. The call is debounced through requestAnimationFrame so
the browser commits the new layout before OverlayScrollbars reads
dimensions.

Verified manually in the compiled binary against PR #509 itself:
opening a small file, clicking pierre's expand-lines control, now
reveals the scrollbar immediately. No regression observed in normal
scroll / click-to-jump / file-switch / annotation-click paths.

For provenance purposes, this commit was AI assisted.
Add the content-resize auto-recompute behavior to OverlayScrollArea's
jsdoc header so the "what does this component do" summary is complete.
The inline comment on the effect already explains the mechanism; this
just surfaces it at the top.

For provenance purposes, this commit was AI assisted.
@backnotprop backnotprop merged commit 57495ec into main Apr 7, 2026
5 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.

[BUG] Can't grab scrollbar

1 participant