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

fix(v2): keep mobile TOC after hydration #5229

Merged
merged 1 commit into from
Jul 28, 2021
Merged

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Jul 27, 2021

Motivation

After we merged the new mobile UX, anchor links in headings broke. The reason for this is that during prerendering we render mobile TOC to avoid layout shift, but after hydration mobile TOC is removed from DOM on desktop. However, this is wrong because we hide mobile TOC on desktop with CSS. Therefore, we need to always render mobile TOC, then anchor links will work again and we still won't have FOUC.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Preview.

Test mobile TOC, then open any anchor link in new tab.

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: bug fix This PR fixes a bug in a past release. label Jul 27, 2021
@lex111 lex111 requested a review from slorber as a code owner July 27, 2021 23:31
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 27, 2021
@netlify
Copy link

netlify bot commented Jul 27, 2021

✔️ [V2]

🔨 Explore the source changes: 1737ce2

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

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

@github-actions
Copy link

⚡️ Lighthouse report for the changes in this PR:

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

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

@github-actions
Copy link

Size Change: -6 B (0%)

Total Size: 859 kB

ℹ️ View Unchanged
Filename Size Change
website/.docusaurus/globalData.json 59.2 kB 0 B
website/build/assets/css/styles.********.css 92.8 kB 0 B
website/build/assets/js/main.********.js 463 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.4 kB 0 B
website/build/blog/index.html 26.4 kB 0 B
website/build/docs/index.html 40.3 kB -3 B (0%)
website/build/docs/installation/index.html 47.9 kB -3 B (0%)
website/build/index.html 27.3 kB 0 B
website/build/tests/docs/index.html 20.9 kB 0 B
website/build/tests/docs/standalone/index.html 18.8 kB 0 B

compressed-size-action

@slorber
Copy link
Collaborator

slorber commented Jul 28, 2021

Thanks, it seems to fix the issue so I'm going to merge this for now.

However, this is wrong because we hide mobile TOC on desktop with CSS. Therefore, we need to always render mobile TOC, then anchor links will work again and we still won't have FOUC.

However I don't agree with that. Rendering the mobile TOC shouldn't need necessary for anchor links to work.

It may be necessary on first load to prevent fouc but for subsequent navigations, not rendering it improves perf as React does not need to insert/update a mobile toc that won't even be displayed.

As it's just a micro-optimization, we can do without for now, and it's better to have good anchor link behavior than this optim.

@slorber slorber merged commit a72ed73 into master Jul 28, 2021
@slorber slorber deleted the lex111/fix-mobile-tco branch August 17, 2021 18:03
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: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants