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

feat(v2): redesign mobile UX: inline TOC + doc sidebar in main menu #4273

Merged
merged 45 commits into from
Jul 9, 2021

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Feb 23, 2021

Note from @slorber : this PR has been marked as a breaking change to draw attention that:

  • the mobile UX is now significantly different
  • multiple theme components were updated, and you may likely update your swizzled components accordingly

Test on mobile the new UX: https://deploy-preview-4273--docusaurus-2.netlify.app/docs/


Motivation

Attempt to resolve #2220.

Closes #4927
Closes #4700

Dirty/draft and apparently improper implementation, very quickly written to demonstrate new navigation UI (TOC) on mobiles (upon request from @markerikson).

The main idea is to render the doc sidebar content on mobiles in the navbar sidebar and also add a new sticky button to display the local l (by document) TOC. This gives us place for the back to top button.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

ezgif com-gif-maker (19)

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: new feature This PR adds a new API or behavior. label Feb 23, 2021
@lex111 lex111 requested a review from slorber as a code owner February 23, 2021 12:03
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Feb 23, 2021
@netlify

This comment has been minimized.

@netlify
Copy link

netlify bot commented Feb 23, 2021

✔️ [V2]

🔨 Explore the source changes: 3dd78dc

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/60e85f99b4bcbe00087d3d6e

😎 Browse the preview: https://deploy-preview-4273--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Feb 23, 2021

Size Change: -30.9 kB (-3%)

Total Size: 965 kB

Filename Size Change
website/build/assets/css/styles.********.css 89.1 kB +1.48 kB (+2%)
website/build/assets/js/main.********.js 458 kB +10.7 kB (+2%)
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.4 kB -6.48 kB (-9%)
website/build/blog/index.html 26.3 kB -6.35 kB (-19%) 👏
website/build/docs-tests/index.html 124 kB -6.54 kB (-5%)
website/build/docs-tests/standalone/index.html 19.1 kB -6.17 kB (-24%) 🎉
website/build/docs/index.html 46 kB -5.41 kB (-11%) 👏
website/build/docs/installation/index.html 53.3 kB -5.82 kB (-10%) 👏
website/build/index.html 27.3 kB -6.29 kB (-19%) 👏
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 58.8 kB

compressed-size-action

@markerikson

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Feb 24, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 90
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4273--docusaurus-2.netlify.app/

@markerikson
Copy link

The last commit looks like it fixed the "ToC popup doesn't hide when link tapped" issue, but for some reason the popup is still empty of any link content in Chrome for Android.

@slorber
Copy link
Collaborator

slorber commented Feb 24, 2021

That looks pretty cool, thanks for working on this!

Some design feedbacks:

  • I think the mobile TOC does not show the links with dark mode
  • The mobile TOC view is too "square". I think something more centered as a large modal, not touching the edges of the screen, could look better (even if it reduces the toc surface).
  • Should we separate regular navbar items from the sidebar in a more explicit way?

From a technical perspective, will have to take a deeper look.

My initial idea was to avoid using the global data API for this feature because the data is "global", ie it is available on all the pages of the site, and having a long sidebar means it impacts the whole site performance (including the homepage, and we have Docusaurus sites with huge sidebars like this one: https://xsoar.pan.dev/docs/reference/index)

What I would try is to replace the global data API with a "portal" / "slot-fill" library:

  • you declare a slot in the sidebar, like "sidebar-top" in your implementation
  • you let the document page fill that slot from another place in the JSX (ie directly in the Doc page JSX)

The problem is that afaik there's no up-to-date maintained lib that supports SSR:

Maybe we don't need to support SSR for the mobile sidebar (as we don't display the sidebar before the user click on the hamburger menu, there wouldn't be FOUC), but at the same time it may be important for SEO to render that sidebar in the markup as crawlers are mobile-first? (don't know if this matters because anyway it's hidden before you open the mobile menu)

I would try to use react-teleport instead of the global data API and see if this can solve the use-case in a more efficient way

@lex111
Copy link
Contributor Author

lex111 commented Feb 24, 2021

the popup is still empty of any link content in Chrome for Android.

@markerikson could you please give more details on this (source, screenshots)? I tested in this browser and didn't notice this issue.


@slorber Why is using global data bad in this case? It seems to me that this approach works well, especially since we can remove the permalinkToSidebar field, which you marked as not very useful.
I agree that the current way is probably not well suited for large docs sites, and certain conditions (proper navbar items) are needed to display sidebar contents on mobiles. I have another idea of how to present this menu, but I would like to try to implement it also via using global data, so honesty I don't really like the suggestion with portal.

@armano2

This comment has been minimized.

@slorber
Copy link
Collaborator

slorber commented Mar 23, 2021

Yes that's what I reported.

@lex111 go ahead with global data for now, as sidebars data is not huge and I'll try to see if I can refactor/optimize that later.

It's better to have this feature asap even if it's not the ideal implementation IMHO, and we don't document docs global data APIs on purpose currently so we can do breaking changes on it later.

@slorber
Copy link
Collaborator

slorber commented May 12, 2021

FYI for sites with a very large sidebar, rendering the sidebar on the server for each doc page is expensive (cf #4753, just the sidebar increase a site's build time by 12 minutes!)

We should test this new mobile UX against such a large site and see the potential impacts on build time and runtime perf.
This mobile drawer is not displayed before hydration so we can probably render this sidebar only on the client.

@ndom91

This comment has been minimized.

@lex111
Copy link
Contributor Author

lex111 commented May 16, 2021

Sorry for such a long wait! I decided to completely rethink previous UI design, and the obtained result seems to me to be the best user experience:

TOC of page is available as a collapsible panel by pressing button in front of the document heading, and the sidebar contents are displayed as a separate app-like menu. Hope you enjoy this option.

Traditionally, there is internal implementation needs refactoring, and the styles do not fully support dark mode. This will all be fixed after we come to a final decision.

ezgif com-gif-maker (1)

@ndom91
Copy link
Contributor

ndom91 commented May 16, 2021

@lex111 this looks great! I really like the inline collapsible TOC - great solution for mobile!

@markerikson
Copy link

Hmm. I appreciate the effort that went into this, but I'm not convinced it's the right approach.

It looks to me like any time I want to access the in-page TOC, I'd first have to scroll all the way back up to the top of the page to expand that dropdown. That could easily get annoying on long docs page.

This was actually a great thing about having the floating button. It's accessible no matter how far down you've scrolled on the current page.

Personally I'd still really like to see the approach I first suggested: keep the floating button, and use that to trigger showing the in-page TOC.

@lex111
Copy link
Contributor Author

lex111 commented May 16, 2021

It looks to me like any time I want to access the in-page TOC, I'd first have to scroll all the way back up to the top of the page to expand that dropdown. That could easily get annoying on long docs page.

I was thinking about that. But later we will have "back to top" button that will make it easier to go to TOC collapsible panel. So given that, I don't want to clutter the interface with two floating buttons. Make sense for you?

@markerikson
Copy link

Heh. Having any way to access the page TOC on mobile is an improvement over what we've got now :) To me, having that floating button bring up a TOC overlay makes the most sense design-wise, but since you're the one implementing this and I'm over here in the peanut gallery, I can't complain too much - I'll take whatever actually gets implemented at this point.

@lex111
Copy link
Contributor Author

lex111 commented May 16, 2021

Thank you for understanding ;)

In fact, I researched a lot of docs sites to come up with this new solution that I feel is most appropriate for needs of all users. As always, my concern is for users to focus on the main thing on site -- its content. And the current UI is the best way to do that (imo).

@ndom91
Copy link
Contributor

ndom91 commented May 17, 2021

My 2 cents - although I can understand and respect the idea of the floating button allowing access to the TOC no matter where one is currently scrolled on the page, I have to say in my experience I find those floating buttons mostly annoying / blocking the view of the content and rarely use them.

I think a "back to the top" and then having the TOC there, like @lex111 has in their latest update is a perfectly fine compromise.

@pranabdas
Copy link
Contributor

@slorber I think the redux website gives double options (same items in navbar and sidebar). Once I pulled the sidebar, I can navigate from there. I don't really need to go Back to main menu in order to get the same sidebar. But this certainly makes sense if one has super long sidebar that would save one from scrolling up/down. You select any item in the main menu, you get the same sidebar but at different vertical scroll positions.

I think if an item has sidebar, the expanded sidebar should stay there to let me choose. If different items on the main menu has separate sidebars, it feels abrupt otherwise. If one touches outside the expanded sidebar to hide it after selecting on the main menu, the behaviour should be as it is now. Just my thoughts. Thank you.

@slorber
Copy link
Collaborator

slorber commented Jul 8, 2021

Once I pulled the sidebar, I can navigate from there. I don't really need to go Back to main menu in order to get the same sidebar.

Think about the user being on the homepage and clicking a navbar item. It's not even about going back, but what to expect on a navbar item click. With your UX, to access the Redux tutorial, it requires to press first on the sidebar tutorial element, and then to press on the sidebar overlay to close the sidebar (which is showing the docs sidebar, focusing on the tutorial element). Do we really want the user to press 2 times in this case? @markerikson any thoughts?

I think if an item has sidebar

Technically we currently can't know if a navbar item belongs to a doc inside a sidebar, or an "orphan doc" without sidebar. This is because of the modular nature of Docusaurus: not all the data are available everywhere and we try to keep the "global data" (available on the homepage, blog etc...) very small because it impacts the perfs of your whole site.

Having a new navbar item of type docsSidebar would solve this problem because we could just say "if type === docsSidebar", then show the sidebar secondary panel (docs sidebar) instead of closing it.

We could also have a boolean on navbar items to tell if the mobile sidebar should be closed on click or not.
Both UX makes sense so we should rather not force users of the docs navbar item type to use one UX in particular when they want the other, but make this behavior configurable and explicit.

I already planned to implement the docsSidebar navbar item type, because it make sense when you want to implement some kind of "tab system", like seen on RN site (https://reactnative.dev/ => Docs / Components / API) where each 3 navbar item is linked to a distinct sidebar. Passing the first docId of each sidebar is a weird API to achieve that.

The question is: would this new sidebar item type solve your problem? Would you be able to replace your docs types with docsSidebar instead?

# Conflicts:
#	.github/workflows/v2-build-size-report.yml
#	packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx
@pranabdas
Copy link
Contributor

Yes, a new docWithSidebar type would give more flexibility. Hopefully it inherits all other properties from the doc type (I am not sure where else it is being used). Thank you.

@slorber
Copy link
Collaborator

slorber commented Jul 9, 2021

Thanks @pranabdas , actually tried to see how to make this UX work but it's not easy/possible in current state because our layout/navbar unmount/remount after each navigation and lose its opened state. This requires more complex refactorings to make this UX possible, so we'll figure this out in another PR later

@slorber
Copy link
Collaborator

slorber commented Jul 9, 2021

Let's merge this! 🎊

Please test this on your sites with https://docusaurus.io/community/canary

@swyxio
Copy link
Contributor

swyxio commented Jul 9, 2021

@slorber thank you so much! i found a weird inconsistency when opening/closing menus - sometimes it would go to main menu, sometimes it would go to the TOC menu, and it doesnt seem very predictable:

https://www.loom.com/share/d1ede4c5c04f41e9bd92785dcdac0e89 i havent figured out the cause yet, just reporting. i also dont think it should be a blocker since its already an improvement

@slorber
Copy link
Collaborator

slorber commented Jul 10, 2021 via email

kdrag0n added a commit to kdrag0n/protonaosp.kdrag0n.dev that referenced this pull request Jul 10, 2021
I don't see any major issues with this version, and mobile usability has
improved significantly [1], so let's ship it.

[1] facebook/docusaurus#4273
@slorber
Copy link
Collaborator

slorber commented Jul 13, 2021

@sw-yx I was wondering why the mobile collapsible TOC does not show up here:

image

Do you have a PR / preview so that I can inspect it more easily? I can also open a PR to the temporal doc if you want, and we try to get everything working properly here.

kdrag0n added a commit to kdrag0n/protonaosp.kdrag0n.dev that referenced this pull request Jul 13, 2021
@swyxio
Copy link
Contributor

swyxio commented Jul 14, 2021

ah sorry just saw this! no i didnt have a separate PR opened, i just bumped versions to canary in local dev. thanks for handling it anyway!!!

UtsavBalar1231 pushed a commit to UtsavBalar1231/docusaurus that referenced this pull request Jul 24, 2021
We're on canary because of [1]. Upgrade for [2] and [3].

[1] facebook/docusaurus#4273
[2] facebook/docusaurus#5157
[3] facebook/docusaurus#5159

Change-Id: Ic11b4480368fde47a82bd9613513972c51ffd8eb
amithm7 added a commit to celzero/docs that referenced this pull request Aug 14, 2021
@slorber slorber deleted the lex111/iss2220 branch August 17, 2021 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: breaking change Existing sites may not build successfully in the new version. Description contains more details. pr: new feature This PR adds a new API or behavior.
Projects
None yet
8 participants