Repository navigation
fix(ui): keep the composer text overlay aligned with the textarea when a classic scrollbar appears - #1530
Merged
Conversation
…n a classic scrollbar appears The skill-reference composer paints its glyphs with a mirror <div> over a transparent-text textarea; only the caret still comes from the textarea. When a layout-consuming vertical scrollbar appears (Windows/Linux classic scrollbars, ~12px under the app's `scrollbar-width: thin`), the textarea's line box narrows by the scrollbar width while the `overflow: hidden` mirror keeps its full width, so from the first line whose wrap point differs the caret is drawn away from the glyph it belongs to. Measure the scrollbar in the existing scroll/value sync and mirror it onto the overlay's right padding, with a ResizeObserver so a resize that adds or drops the scrollbar without a keystroke re-syncs too. Base padding and border widths are read from the textarea's computed style rather than hardcoded. When the measured width is 0 (macOS/iOS overlay scrollbars, touch) nothing is written at all, so those surfaces keep byte-identical DOM. Fixes #1525
Guards the four failures that matter: the mirror not picking up the scrollbar width, an inline style being written where the scrollbar takes no layout (macOS/touch must stay unchanged), a stale gutter left behind when the scrollbar goes away, and the ResizeObserver path that catches a resize with no keystroke. happy-dom has no layout engine, so the textarea's box metrics are stubbed.
This was referenced Sep 15, 2026
1 task
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.
Fixes #1525
Root cause
ComposerTextareapaints the composer's visible glyphs with a mirror<div>(absolute inset-0,overflow: hidden) over a textarea whose own text is transparent — only the native caret still comes from the textarea. When the textarea reachesmax-h-64and grows a layout-consuming vertical scrollbar (Windows/Linux classic scrollbars; the app's globalscrollbar-width: thinmakes them ~12px), the textarea's line box shrinks by that width while the mirror's does not, so from the first line whose wrap point differs the caret is drawn away from the glyph it belongs to. macOS/iOS overlay scrollbars consume no layout, which is why the bug is invisible there.The fix
One measurement inside the existing
syncScrollcallback, mirrored onto the overlay's right padding:offsetWidth - clientWidthminus the computed left/right border widths, so a border added later can never be mistaken for a scrollbar;COMPOSER_TEXT_CLASSESchanges;ResizeObserveron the textarea re-runs the sync, becausesyncScrollotherwise only fires on scroll and on value change — a window/panel resize that adds or drops the scrollbar without a keystroke would leave the gutter stale;offsetWidth - clientWidthis unchanged the sync returns before it touchesgetComputedStyleor the DOM.scrollbar-gutter: stablewas tried and cannot work here — it is ignored on anoverflow: hiddenbox, and making the mirror a scroll container can't guarantee the same scrollbar kind as the textarea.Zero-change guarantee where the bug can't occur
When the measured scrollbar width is 0, the code writes no inline style at all — it does not write the same number inline, it does not create a
styleattribute, it takes no DOM write of any kind. macOS, iOS and every touch/compact surface therefore render a byte-identical DOM tomain. This is asserted two ways:overlay.getAttribute('style') === nullafter typing past the max height with a 0px delta, andinline=nullat every typing stage (below).Risk analysis
Windows/Linux users (the fix): once the composer overflows, the mirror gains
padding-right: base + scrollbarWidth. The caret lands on its glyph, and the overlay stops painting text underneath the scrollbar. Nothing else about the composer changes — no layout of the popover, no scroll behavior, no IME path (the composing branch still hides the overlay and shows the native text).macOS / touch / compact users: nothing. No inline style is ever written, so the rendered DOM and computed styles are what they are today. Proven by the test and the macOS Playwright control.
Performance: the sync already read
el.scrollTop/scrollLeft; it now also readsoffsetWidth/clientWidthin the same reads-before-writes block, so a sync still costs at most one forced layout.getComputedStyleruns only when the measured delta actually changes (typically once, when the scrollbar appears, and once when it disappears), never per keystroke or per scroll event.Failure modes, all degrading to today's behavior: no
ResizeObserverin the environment → the observer is never created and the scroll/value-change path still carries the fix; computedpadding-rightunparsable → any applied gutter is cleared and nothing is written; a remounted overlay invalidates the memo, so a staleappliedvalue can never suppress a needed write.Not exercised: real Windows and real Linux hardware. The classic-scrollbar geometry was reproduced in Chromium on macOS with a genuine
::-webkit-scrollbar { width: 12px }(see below), not emulated with padding. Firefox and Safari were not driven; both take the same code path, and on Safari/macOS the measured width is 0, i.e. the no-write branch.Consumer audit
ComposerTextareais module-private toCommentPopover.tsxand used only by its popover and dialog modes, and the mirror only exists whenskillReferencesis on. Everything below reaches it throughCommentPopover:Viewer.tsx)PlanCleanDiffView.tsx)HtmlViewer.tsx, incl. the global-comment popover)GoalSetupSurface.tsx), code-file popout (CodeFilePopout.tsx)DiffViewer,AllFilesCodeView,PRCommentsTab,AnnotatableDescription,CallFlowTreeView,CallFlowRawView,ReviewPRArtifactsPanelCommentPopoverwithskillReferencesoff<textarea>; no overlay exists andsyncScrollreturns earlyDecisionNoteField/DecisionNoteDialog(header decision composer, sidebar "+ General comment")<textarea>, no mirror — untouchedCommentPopoveris stubbed out at build time (read-only-stubs-plugin.ts)Nothing else in the repo sets
paddingRight(or any style) on[data-skill-ref-overlay]; the only other inline style on that element is React's ownvisibilityduring IME composition, and React never clears properties it did not render.Test plan
packages/ui/components/CommentPopover.overlayGutter.test.tsx(new, DOM-gated): base + 12px gutter with a 12px delta; borders counted as borders, not scrollbar; no inline style at all at 0px; the gutter removed when the scrollbar goes away; the ResizeObserver path re-syncing without a keystroke and disconnecting on unmount; and the no-ResizeObserverenvironment. 5 of the 6 fail against the unfixed component (the sixth is the zero-change guarantee, which must pass both before and after).bun run typecheck— clean.DOM_TESTS=1 bun test packages/ui packages/editor packages/review-editor— 2164 pass / 5 fail, against a 2158 pass / 5 fail baseline onmain: the same five order-dependentDocBadges/artifactDocumentfailures, which pass in isolation on both.bun run --cwd packages/ui smoke:package— packs and resolves.bun run --cwd apps/review build && bun run build:hook— both clean.Playwright, real app, real classic scrollbar
Annotate surface driven in Chromium (
--hide-scrollbarsdisabled,::-webkit-scrollbar { width: 12px }injected into the test page only), typing prose into the comment composer until it overflows.OFFSETis the horizontal distance between where the textarea lays the caret out and where the overlay paints the glyph before it.padding-rightWorst case: 167.77px → 0.00px.
macOS control (same script, no scrollbar injection), every stage through 1080 chars:
scrollbar=0px,ovPadRight=4px,inline=null,OFFSET=0.00px— identical to the run against the unfixed build.