fix(theme-default): stabilize horizontal layout across pages with/without vertical scrollbar#5198
Open
rickyly wants to merge 1 commit into
Open
fix(theme-default): stabilize horizontal layout across pages with/without vertical scrollbar#5198rickyly wants to merge 1 commit into
rickyly wants to merge 1 commit into
Conversation
94b9dcb to
fdc57cd
Compare
…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.
fdc57cd to
56f02cc
Compare
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.
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, andVPLocalNav.vueuses
100vwto compute a centering offset inside an@media (min-width: 1440px)block.100vwis constant across scroll states (always includesthe scrollbar gutter per spec), but the container these paddings apply to
has
width: 100%and therefore trackshtml.clientWidth, which shrinks bythe scrollbar width when the scrollbar appears.
Fix
Set
overflow-y: scrollonhtmlso the scrollbar gutter is alwaysreserved, making
html.clientWidthconstant and the layout pixel-stableacross navigations.
Why not
scrollbar-gutter: stableTested first; produced no effect on the wobble in the reporter's browser,
suggesting incomplete propagation of the property to viewport-relative
measurements.
overflow-y: scrollis the universal, lowest-friction fix.Verified on
vitepress 1.6.4 (the CSS construct is unchanged on
mainas of this PR).Compatibility
short pages; layout is now stable.