Skip to content

fix(theme-default): stabilize horizontal layout across pages with/without vertical scrollbar#5198

Open
rickyly wants to merge 1 commit into
vuejs:v1from
rickyly:fix/scrollbar-wobble
Open

fix(theme-default): stabilize horizontal layout across pages with/without vertical scrollbar#5198
rickyly wants to merge 1 commit into
vuejs:v1from
rickyly:fix/scrollbar-wobble

Conversation

@rickyly

@rickyly rickyly commented May 22, 2026

Copy link
Copy Markdown

Summary

On browsers using classic (space-occupying) vertical scrollbars, navigating
between a page that triggers the scrollbar and one that does not causes the
top nav, content area, and local nav to shift horizontally by ~15 px at
viewport widths >= 1440 px. Reproduces on default Chrome/Edge on Linux/Windows.

Root cause

The desktop layout in VPNavBar.vue, VPContent.vue, and VPLocalNav.vue
uses 100vw to compute a centering offset inside an @media (min-width: 1440px) block. 100vw is constant across scroll states (always includes
the scrollbar gutter per spec), but the container these paddings apply to
has width: 100% and therefore tracks html.clientWidth, which shrinks by
the scrollbar width when the scrollbar appears.

Fix

Set overflow-y: scroll on html so the scrollbar gutter is always
reserved, making html.clientWidth constant and the layout pixel-stable
across navigations.

Why not scrollbar-gutter: stable

Tested first; produced no effect on the wobble in the reporter's browser,
suggesting incomplete propagation of the property to viewport-relative
measurements. overflow-y: scroll is the universal, lowest-friction fix.

Verified on

vitepress 1.6.4 (the CSS construct is unchanged on main as of this PR).

Compatibility

  • Overlay-scrollbar browsers (macOS Safari, mobile Chrome): no visual change.
  • Classic-scrollbar browsers: a thin inactive scrollbar track appears on
    short pages; layout is now stable.
  • Pure CSS, no JS or markup change.

@rickyly rickyly force-pushed the fix/scrollbar-wobble branch from 94b9dcb to fdc57cd Compare May 22, 2026 12:51
…hout vertical scrollbar

On browsers using classic (space-occupying) vertical scrollbars, navigating
between a page that triggers the scrollbar and one that does not caused the
top nav, content area, and local nav to shift horizontally by ~15 px at
viewport widths >= 1440 px. The desktop layout's `100vw`-based centering
math is constant, but the container it applies to has `width: 100%` and
therefore tracks `html.clientWidth`, which shrinks when the scrollbar
appears.

Setting `overflow-y: scroll` on `html` reserves the scrollbar gutter at all
times, making `html.clientWidth` constant and the layout pixel-stable
across navigations. Overlay-scrollbar browsers (macOS Safari, mobile
Chrome) are unaffected since overlay scrollbars never consumed layout
space.

`scrollbar-gutter: stable` was considered but produced no effect in the
reporter's browser, suggesting incomplete propagation of the property to
viewport-relative measurements; `overflow-y: scroll` is the universal,
lowest-friction fix.
@rickyly rickyly force-pushed the fix/scrollbar-wobble branch from fdc57cd to 56f02cc Compare May 22, 2026 12:57
@rickyly rickyly changed the base branch from main to v1 May 22, 2026 12:57
@github-actions github-actions Bot added the stale label Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant