Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(site): prevent layout shift when opening dropdowns on /agents page - #22448

Merged
DanielleMaywood merged 1 commit into
mainfrom
fix/agents-dropdown-layout-shift
Mar 1, 2026
Merged

fix(site): prevent layout shift when opening dropdowns on /agents page#22448
DanielleMaywood merged 1 commit into
mainfrom
fix/agents-dropdown-layout-shift

Conversation

@DanielleMaywood

Copy link
Copy Markdown
Contributor

Problem

Opening any dropdown (Select, DropdownMenu) on the /agents page caused visible layout shift.

The agents page previously overrode the global scrollbar-gutter: stable to auto on <html> to reclaim the unused gutter space (the page uses internal scroll containers). This broke the global body[data-scroll-locked] CSS in index.css, which assumes stable gutter is always active.

When a Radix dropdown opened, two mechanisms caused the shift:

  1. react-remove-scroll-bar gap compensation — it measures window.innerWidth - document.documentElement.clientWidth. With scrollbar-gutter: stable the gutter is reserved even without overflow, so the gap is non-zero and the library injects padding-right/margin-right on <html>/<body>.

  2. Global overflow-y: scroll !important — the CSS rule on html body[data-scroll-locked] forces a scrollbar onto <body> when Radix locks scroll, creating a scrollbar that never existed on this page.

Fix

A single useEffect in AgentsPage.tsx that:

  • Sets overflow: hidden on both <html> and <body> so neither can produce a scrollbar.
  • Sets scrollbar-gutter: auto on <html> so the browser stops reserving gutter space, making react-remove-scroll-bar measure a gap of 0.
  • Injects a <style> tag (html body[data-scroll-locked] { overflow-y: hidden !important }) that overrides the global rule with matching specificity, winning by source order.

Everything is cleaned up on unmount — no other pages are affected.

The agents page opts out of the global scrollbar-gutter: stable because
it uses internal scroll containers and the reserved gutter wastes space.
However, simply setting scrollbar-gutter: auto broke the global
body[data-scroll-locked] CSS fix in index.css, which assumes stable
gutter is always active.

When a Radix dropdown opened, two things caused layout shift:

1. react-remove-scroll-bar measures gap = window.innerWidth -
   document.documentElement.clientWidth. With scrollbar-gutter: stable
   the gutter is reserved even without overflow, so gap > 0 and the
   library injects padding-right/margin-right on html/body.

2. The global CSS rule `html body[data-scroll-locked] { overflow-y:
   scroll !important }` forces a scrollbar onto body when Radix locks
   scroll, creating a scrollbar that never existed on this page.

Fix with a single useEffect that:
- Sets overflow:hidden on both <html> and <body> so neither can produce
  a scrollbar.
- Sets scrollbar-gutter:auto on <html> so the browser stops reserving
  gutter space, making the react-remove-scroll-bar gap measurement 0.
- Injects a <style> tag with matching specificity that overrides the
  global overflow-y:scroll rule on body[data-scroll-locked].

All changes are scoped to the agents page via useEffect cleanup.
@DanielleMaywood
DanielleMaywood marked this pull request as ready for review March 1, 2026 00:11
@DanielleMaywood

DanielleMaywood commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

So janky but it appeared to work for me + should be completely contained to this page

@DanielleMaywood
DanielleMaywood merged commit 17d3d8a into main Mar 1, 2026
31 checks passed
@DanielleMaywood
DanielleMaywood deleted the fix/agents-dropdown-layout-shift branch March 1, 2026 08:01
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants