Repository navigation
Closed as not planned
Labels
bugAn error in the Docusaurus core causing instability or issues with its executiondomain: themeRelated to the default theme components
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
The displayed portion of the content changes visually when switching between the collapsed and expanded states of the sidebar. When I collapsed and then expanded sidebar at the bottom, the page display jumps from the bottom footer to the content section.
Reproducible demo
Steps to reproduce
- Navigate to: https://docusaurus.io/docs/deployment
- Scroll to the bottom
- Collapse the sidebar
- Expand the sidebar
- Try 3 and 4 multiple times (You can notice the vertical shift of web page content)
Demo
video1197996455.mp4
Expected behavior
No content shift when collapsing or expanding the sidebar
Need more expected details from the development team
cc @Josh-Cena
Actual behavior
Before the sidebar is collapsed, the page is at the bottom, but after the sidebar is collapsed and expanded, the page will jump to the Deploying to Layer0 section.
Your environment
- Public site URL: https://docusaurus.io/docs/deployment
- Docusaurus version used: 2.0.0-rc.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows
Self-service
- I'd be willing to fix this bug myself.
Metadata
Metadata
Assignees
Labels
bugAn error in the Docusaurus core causing instability or issues with its executiondomain: themeRelated to the default theme components
Activity
slorber commentedon Aug 9, 2022
Josh-Cena commentedon Aug 9, 2022
slorber commentedon Aug 9, 2022
Josh-Cena commentedon Aug 9, 2022
slorber commentedon Aug 9, 2022
I see now 🤪 thanks for clarifying. The markdown page content has changed from smaller to taller.
So I'm going to move my comment here and remove it from the older issue. 👇👇👇
This behavior is because we toggle from
max-width: 1320pxtomax-width: 1440pxChanging the dimension of the content container leads to some lines wrapping, leading to the layout shift. It's not the sidebar that changes height, but rather the scroll container that changes dimensions as we toggle the sidebar.
You'll notice that the layout shift is more important on larger docs, and at the bottom: this is just because there are more lines wrapping above :)
In the end => larger container VS no layout shift: you can only pick one of those.
I'd say the layout shift is a minor annoyance and usually we want to expand a bit the content container when more space is available.
Technically we could keep the same container size for large desktop screens, but for mobile we absolutely want to increase that container width anyway.
It wouldn't make sense to collapse the sidebar and still keep a small content container (< 500px in the screenshot above).
What I mean is: layout shifts are expected to happen, on purpose, because we want to expand the length of the lines
If you want 0 layout shift, I'd say it's your responsibility to ensure the content container keeps the exact same size. You can do that with CSS. I don't think we'd want Docusaurus to do that by default.
Now, a possible solution to mitigate this layout shift, particularly on very large documents where the layout shift can be significant (like the bottom of our deployment page)
Note we already do something similar when switching tabs (cf #5618), that can also produce layout shifts, and have some util already:
This won't prevent new line wraps in the visible viewport. Not even sure it's worth implementing this.
Is this layout shift a big deal in the first place and annoying some real users?
slorber commentedon Oct 16, 2026
Closing as working as designed. When the docs sidebar is hidden, the doc content gets the freed space on purpose. Lines re-wrap, the page gets shorter, and the browser clamps the scroll position. Expanding the sidebar makes the page taller again, but the scroll position stays where it was clamped.
Still the same on
4.0.0-canary-6972. With a 1280px viewport, scrolled to the bottom of a long doc, the content container goes from 965px to 1235px when the sidebar is hidden, the page height from 22269px to 18732px, and after expanding the sidebar you end up 3537px above the bottom.Repro: https://github.com/slorber/docusaurus-repros/tree/issue-7918
themeConfig.docs.sidebar.hideable: trueand a long docsrc/css/custom.css, off by default, enabled with one line indocusaurus.config.jsIf you prefer no shift over a wider content area, this CSS keeps the content exactly as wide as with the sidebar visible, centered in the freed space:
Verified in the repro: the content width, the page height, and the scroll position at the bottom don't change when toggling the sidebar.
(AI-assisted)