Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content shift when collapsing or expanding the sidebar #7918

Open
2 of 7 tasks
yzhe819 opened this issue Aug 8, 2022 · 5 comments
Open
2 of 7 tasks

Content shift when collapsing or expanding the sidebar #7918

yzhe819 opened this issue Aug 8, 2022 · 5 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: theme Related to the default theme components

Comments

@yzhe819
Copy link
Contributor

yzhe819 commented Aug 8, 2022

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and 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

https://docusaurus.io/docs/deployment

Steps to reproduce

  1. Navigate to: https://docusaurus.io/docs/deployment
  2. Scroll to the bottom
  3. Collapse the sidebar
  4. Expand the sidebar
  5. 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.
@yzhe819 yzhe819 added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Aug 8, 2022
@Josh-Cena Josh-Cena added domain: theme Related to the default theme components and removed status: needs triage This issue has not been triaged by maintainers labels Aug 8, 2022
@slorber

This comment was marked as outdated.

@slorber slorber marked this as a duplicate of #4415 Aug 9, 2022
@slorber slorber closed this as completed Aug 9, 2022
@slorber slorber added the closed: duplicate This issue or pull request already exists in another issue or pull request label Aug 9, 2022
@Josh-Cena

This comment was marked as outdated.

@Josh-Cena Josh-Cena reopened this Aug 9, 2022
@Josh-Cena Josh-Cena removed the closed: duplicate This issue or pull request already exists in another issue or pull request label Aug 9, 2022
@slorber

This comment was marked as outdated.

@Josh-Cena

This comment was marked as outdated.

@slorber
Copy link
Collaborator

slorber commented 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: 1320px to max-width: 1440px

Changing 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.

CleanShot 2022-08-09 at 16 59 46@2x

CleanShot 2022-08-09 at 17 00 12@2x

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.

CleanShot 2022-08-09 at 17 02 14

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)

  • take some content node in the middle of the screen
  • ensure it keeps the exact same viewport position after we have resized the container

Note we already do something similar when switching tabs (cf #5618), that can also produce layout shifts, and have some util already:

const {blockElementScrollPositionUntilNextRender} = useScrollPositionBlocker();

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: theme Related to the default theme components
Projects
None yet
Development

No branches or pull requests

3 participants