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

perf(v2): avoid rerender of sidebar items while scrolling #4603

Merged
merged 1 commit into from
Apr 12, 2021

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Apr 12, 2021

Motivation

Should fix #4589

Currently we use the scroll event to adjust the correct height of the doc sidebar when displaying the announcement bar. To do this we toggle the class if the user scrolls to the top of a page, which in turn causes the while DocSidebar component to be re-rendered at this moment. Since only items in this component are the most memory-consuming elements, I propose to memoize them to mitigate that issue.

useScrollPosition(({scrollY}) => {
setShowAnnouncementBar(scrollY === 0);
});

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

See To Reproduce section in #4589

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: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient. label Apr 12, 2021
@lex111 lex111 requested a review from slorber as a code owner April 12, 2021 13:18
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 12, 2021
@netlify
Copy link

netlify bot commented Apr 12, 2021

[V1]

Built with commit d588f60

https://deploy-preview-4603--docusaurus-1.netlify.app

@netlify
Copy link

netlify bot commented Apr 12, 2021

[V2]

Built with commit d588f60

https://deploy-preview-4603--docusaurus-2.netlify.app

@github-actions
Copy link

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 71
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

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

@github-actions
Copy link

Size Change: 0 B

Total Size: 578 kB

ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.2 kB 0 B
website/build/assets/js/main.********.js 401 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.1 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 26.9 kB 0 B

compressed-size-action

@slorber
Copy link
Collaborator

slorber commented Apr 12, 2021

Thanks

That will help but not 100% sure it totally fixes the problem. Will look at this soon

@slorber slorber merged commit 7c56f81 into master Apr 12, 2021
@slorber slorber deleted the lex111/iss4589 branch August 17, 2021 18:02
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: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DocSidebar performance issues: useless and unoptimized re-renders
3 participants