CopilotKit icon indicating copy to clipboard operation
CopilotKit copied to clipboard

fix(react-core): reserve scrollbar gutter on chat scroll container

Open jerelvelarde opened this issue 6 months ago • 4 comments

Why this matters

In narrow chat layouts — sidebar panels, drawer chats, two-pane apps with a chat column under ~500px — the framework's always-visible 6px scrollbar runs directly through the bottom-right corner of the absolutely-positioned input pill. The scrollbar thumb and the pill's rounded edge occupy the same pixels.

It's a small visual defect with a large reach: any consumer who embeds the chat in anything narrower than a typical full-page layout sees it. For a canonical starter, this is one of the first polish papercuts a developer notices when they move beyond the full-screen demo.

(not the error but the overlap)

image

How it's implemented

Single-line CSS rule in packages/react-core/src/v2/styles/globals.css: scrollbar-gutter: stable on the chat scroll container, scoped to a new data-copilotkit-scroll-container attribute. The attribute is added to the four scroll surfaces inside CopilotChatView.tsx's ScrollView (the StickToBottom.Content pin-to-bottom case, the pin-to-send wrapper, the pre-mount fallback, and the none mode wrapper) so the rule reaches every autoScroll mode.

scrollbar-gutter: stable is the modern CSS primitive for exactly this case — it reserves space for the scrollbar whether the bar is currently visible or not. No JS, no WeakMap-of-timers, no opt-in flag. Works across Chromium, Firefox, and Safari (16.4+).

Scrollbar appearance (width, color, thumb style) is unchanged. Only the gutter reservation is new.

Note: scrollbar-gutter: stable reserves the gutter whether or not the scrollbar is currently visible. In wide layouts, this means a ~6px right-side inset is now reserved on the chat scroll container even when no scrollbar would render. Visually negligible in the default theme; consumers who explicitly want zero gutter can override with scrollbar-gutter: auto.

Migration

Pure addition with no opt-out required for the default case. Apps that explicitly want zero gutter reservation (rare — would mean they want the overlap) can override locally with scrollbar-gutter: auto on [data-copilotkit-scroll-container].

Known parity gap (follow-up)

Vue/Angular counterparts have the same scrollbar-overlap risk in narrow chat layouts — both use overflow-y-scroll on the chat scroll container with an absolutely-positioned input pill, and neither globals.css reserves a gutter. To be addressed in a follow-up PR — left out of this scope to keep the React fix isolated. Confirmed:

  • packages/vue/src/v2/components/chat/CopilotChatView.vue (scroll container line 589, absolute input wrapper line 694)
  • packages/angular/src/lib/components/chat/copilot-chat-view-scroll-view.ts (scroll containers lines 51, 64, 134)
  • packages/angular/src/lib/components/chat/copilot-chat-view-input-container.ts (absolute input wrapper line 76)
  • packages/vue/src/styles/globals.css and packages/angular/src/styles/globals.css (neither sets scrollbar-gutter)

jerelvelarde avatar May 21 '26 14:05 jerelvelarde

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 22, 2026 7:46am

Request Review

vercel[bot] avatar May 21 '26 14:05 vercel[bot]

@jerelvelarde is attempting to deploy a commit to the CopilotKit Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 21 '26 14:05 vercel[bot]

Open in StackBlitz

@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/@copilotkit/a2ui-renderer@4965

@copilotkit/agentcore-runner

pnpm add https://pkg.pr.new/@copilotkit/agentcore-runner@4965

@copilotkitnext/angular

pnpm add https://pkg.pr.new/@copilotkitnext/angular@4965

@copilotkit/core

pnpm add https://pkg.pr.new/@copilotkit/core@4965

@copilotkit/react-core

pnpm add https://pkg.pr.new/@copilotkit/react-core@4965

@copilotkit/react-native

pnpm add https://pkg.pr.new/@copilotkit/react-native@4965

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/@copilotkit/react-textarea@4965

@copilotkit/react-ui

pnpm add https://pkg.pr.new/@copilotkit/react-ui@4965

@copilotkit/runtime

pnpm add https://pkg.pr.new/@copilotkit/runtime@4965

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/@copilotkit/runtime-client-gql@4965

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/@copilotkit/sdk-js@4965

@copilotkit/shared

pnpm add https://pkg.pr.new/@copilotkit/shared@4965

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/@copilotkit/sqlite-runner@4965

@copilotkit/voice

pnpm add https://pkg.pr.new/@copilotkit/voice@4965

@copilotkit/vue

pnpm add https://pkg.pr.new/@copilotkit/vue@4965

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/@copilotkit/web-inspector@4965

commit: 2bf9b60

pkg-pr-new[bot] avatar May 21 '26 14:05 pkg-pr-new[bot]

Automated review

Verdict: Looks good — narrow scope, correct CSS primitive for the job, complete coverage of the four runtime scroll surfaces. One small behavior-change note worth flagging in the PR body, no blockers.

Scope and correctness

The diff is 15 additions / 1 deletion across two files:

  • packages/react-core/src/v2/styles/globals.css — one new rule [data-copilotkit] [data-copilotkit-scroll-container] { scrollbar-gutter: stable; } with a multi-line comment explaining the why.
  • packages/react-core/src/v2/components/chat/CopilotChatView.tsx — adds data-copilotkit-scroll-container to four scroll surfaces (lines 474, 564, 691, 710).

scrollbar-gutter: stable is the right primitive — it's the W3C-spec mechanism for exactly this case (reserve gutter even when bar isn't visible, avoid content reflow when overflow toggles). No JS, no opt-in flag, no perf cost.

Scroll-surface coverage (verified)

grep -n "overflow" packages/react-core/src/v2/components/chat/CopilotChatView.tsx returns four elements with overflow-y-auto:

Line Element Mode Has attribute
475 StickToBottom.Content pin-to-bottom yes (474)
565 PinToSendScrollContainer inner <div> pin-to-send yes (564)
692 Pre-mount fallback <div> hydration yes (691)
712 none-mode wrapper <div> manual yes (710)

Coverage is complete. The only other overflow-y-auto in react-core/src/v2/components/chat/ is the mention-list popover at CopilotChatInput.tsx:972 (max-h-64 overflow-y-auto) and the dropdown content at ui/dropdown-menu.tsx:46. Both are bounded popovers, not chat scroll surfaces — correctly excluded. No false negatives, no false positives.

Browser support

scrollbar-gutter: stable requires Chromium 94+ (Sep 2021), Firefox 97+ (Feb 2022), Safari 16.4+ (Mar 2023).

  • No .browserslistrc or browserslist field in packages/react-core/package.json.
  • The file already uses oklch() for scrollbar-thumb colors at line 191 (Safari 15.4+, Chrome 111+, Firefox 113+) — a higher floor than scrollbar-gutter: stable. So this PR doesn't raise the de-facto browser support bar at all; in older browsers the property is silently ignored, which is the desired progressive-enhancement behavior (the input-pill papercut returns, nothing else breaks).

Visual impact in non-narrow layouts

Worth being explicit: stable reserves the 6px gutter whether the scrollbar is currently visible or not. In wide layouts where content doesn't overflow, that's a 6px inset on the right that wasn't there before. This is the correct trade-off (and matches the comment's "doesn't reflow when overflow toggles" rationale), but the PR body's "Scrollbar appearance is unchanged" framing is slightly understated — the gutter reservation itself is a visible change in non-overflowing wide layouts. Not a blocker, just worth a sentence in the PR description so reviewers don't expect zero visual delta.

If a no-gutter-when-not-overflowing variant is ever desired, stable both-edges or auto could be exposed as a token, but stable is the right default.

Attribute naming consistency

Consistent with the data-copilotkit-<role> pattern that PR #4962 (still open) introduces with data-copilotkit-root. Both PRs nest scoping under [data-copilotkit] parent selector, matching the surrounding rule style in globals.css. If both land, the namespace stays coherent: data-copilotkit (descendants for variable scoping) / data-copilotkit-root (top-level chat container) / data-copilotkit-scroll-container (scroll surfaces).

Other notes

  • The descendant combinator [data-copilotkit] [data-copilotkit-scroll-container] requires the scroll container to be inside a [data-copilotkit] ancestor. All four sites render inside CopilotChatView's <div data-copilotkit> wrapper at line 388, so scoping holds in every runtime path.
  • Tests in CopilotChatView.slots.e2e.test.tsx query .overflow-y-auto — unaffected since className strings are unchanged.
  • No slot API, prop, or layout-class change. Theming surface unchanged for consumers.
  • CSS comment is well-written and motivates the stable choice over auto. Keep it.

Suggested (optional, non-blocking)

  • Add one sentence to the PR body acknowledging the 6px gutter is now reserved in wide layouts even when the scrollbar isn't visible — sets expectations for visual-regression-test runs and for screenshot-based downstream consumers.
  • Consider a Playwright/Vitest visual snapshot for the narrow-layout case (≤500px chat column) as a regression guard, since the whole motivation is a layout-width-dependent papercut.

jerelvelarde avatar May 22 '26 07:05 jerelvelarde