docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

fix: docs sidebar layout issue when announcementBar visible

Open sbeaury opened this issue 3 years ago • 12 comments

Pre-flight checklist

  • [x] I have read the Contributing Guidelines on pull requests.
  • [ ] If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • [ ] If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

  • Fix overlapping issue in docs sidebar (Sidebar Ad vs Collapse Button). Subtracted announcement bar height from sidebarViewport max-height
  • Not sure why margin-bottom for DocSidebar is set to var(--docusaurus-announcement-bar-height)

Test Plan

Can easily be double-checked / manually tested on the specific breakpoint causing issue.

Test links

N/A

Related issues/PRs

Issues 8370 and 8374

sbeaury avatar Dec 31 '22 23:12 sbeaury

Hi @sbeaury!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar Dec 31 '22 23:12 facebook-github-bot

[V2]

Built without sensitive environment variables

Name Link
Latest commit 2d4182697c3f7e2d6674c86817f71bca3059bb76
Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6403563dd0c8270008be0192
Deploy Preview https://deploy-preview-8493--docusaurus-2.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Dec 31 '22 23:12 netlify[bot]

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 85 🟢 97 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 72 🟢 100 🟢 100 🟢 100 🟢 90 Report

github-actions[bot] avatar Dec 31 '22 23:12 github-actions[bot]

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot avatar Jan 01 '23 01:01 facebook-github-bot

thank you for your effort however i think it's not good to changing css (ex. use 40px) simply.

#8377 how about checking slorber's comment?

Djunnni avatar Jan 02 '23 11:01 Djunnni

hey @Djunnni, the purpose of this PR is actually to remove the extra 30px from the navbar height (100vh) coming from --docusaurus-announcement-bar-height to avoid things getting squeezed at the bottom. I found this CSS-only solution much simpler than changing the whole layout and it works on the specific breakpoint causing issue (smaller viewport height). The only issue is to reset the max-height to 100vh when announcementBar is NOT visible but should be easy to add a conditional and fix it.

Capture

sbeaury avatar Jan 02 '23 14:01 sbeaury

if announcementBar is hide, sidebar has empty space like that. image could you test this?

Djunnni avatar Jan 03 '23 02:01 Djunnni

(don't worry about the tests, already fixed in main)


This is a nice attempt but unfortunately it doesn't seem to work. It replaces a problem by another (not necessarily better).

Good pages to test:

  • https://docusaurus.io/docs/sidebar/items

  • https://deploy-preview-8493--docusaurus-2.netlify.app/docs/sidebar/items

  • https://docusaurus.io/tests/docs/toc/toc-_-5/

  • https://deploy-preview-8493--docusaurus-2.netlify.app/tests/docs/toc/toc-_-5/

When you start scrolling when announcementBar is visible (clear localstorage or anonymous session), this leads to this weird empty space:

CleanShot 2023-01-05 at 12 08 42@2x

slorber avatar Jan 05 '23 11:01 slorber

As mentioned above, my PR was to fix the overlap when announcementBar is visible. What we know for sure is that .sidebarViewport is too high when announcement bar is visible hence the squeezing at the bottom. But we can use the same idea and monitor how much space that announcement bar takes while scrolling (e.g. interceptor) and subtract it using a CSS-in-JS solution. Could even be integrated into useAnnouncementBar. Or... just refactor the whole layout. I can work out something on my side but it's fine to close the PR for now bc I don't want to hold it off.

style={{maxHeight: `calc(100vh - ${announcementBarHeightOnViewport})`}}

sbeaury avatar Jan 05 '23 14:01 sbeaury

I'm not sure exactly what's the problem and what's the solution is 😅 unfortunately I need to focus on the MDX 2 migration atm.

The only thing I know is that the outcome of merging this PR is not better, eventually worst than the current state.

We want the layout to be fully fixed. We want a solution that doesn't do any of these 2 behaviors:

CleanShot 2023-01-05 at 16 04 11@2x CleanShot 2023-01-05 at 16 04 31@2x

Feel free to close the PR if you think you can't solve it. Thanks for trying, that almost looked like a good solution 😄

slorber avatar Jan 05 '23 15:01 slorber

Last commit should fix the problem hopefully 🤞. I dynamically subtracted the portion of the announcement bar visible on viewport from the sidebar container's max-height.

sbeaury avatar Jan 06 '23 22:01 sbeaury

getComputedStyle can't be used during the SSR/SSG/build phase so this change makes the site unable to build 😅

Not 100% sure it's possible but I'd prefer if we could find a CSS-only solution so that the initial render (before JS is executed) looks fine. "fixing things" with JS usually leads to annoying layout shifts. But a JS solution is still better than no solution 😅 .

slorber avatar Jan 19 '23 13:01 slorber

you're right I forgot to add a conditional using useIsBrowser for client side only but I finally opted out for another solution in my last commit which is to declare a docusaurusAnnouncementBarHeight value in CSS module so that we can export it and use to initialize announcement barheightOnViewport. IMHO a CSS-only solution is not feasible atm since the banner height is kind of dynamic on viewport so the sidebar needs to resize accordingly (unless the whole layout is refactored). There are some build errors in the log that I believe are not linked to my last commit?

sbeaury avatar Jan 20 '23 01:01 sbeaury

Now it builds but does not really work 😄 I see many weird issues on both pages:

  • https://deploy-preview-8493--docusaurus-2.netlify.app/tests/docs/toc/toc-_-5/
  • https://deploy-preview-8493--docusaurus-2.netlify.app/docs/sidebar/items

Will have to investigate later to see what might be the problem.

slorber avatar Mar 08 '23 18:03 slorber

Thanks for giving it a try.

For now I'm going to close all the pending PRs trying to solve this issue, see https://github.com/facebook/docusaurus/issues/8370#issuecomment-1500129085

slorber avatar Apr 07 '23 09:04 slorber