Repository navigation
refactor: cleanup scroll handlers - #5709
Conversation
| setShow(true); | ||
| } | ||
| }, | ||
| [location], |
There was a problem hiding this comment.
To check location we now use useLocationChange hook everywhere, this will better distinguish between scroll and location event handlers.
| const isFirst = useRef<boolean>(true); | ||
|
|
||
| useEffect(() => { | ||
| // Prevent first effect to trigger the listener on mount |
There was a problem hiding this comment.
This is unnecessary code, it used to be needed to fix #5020, but it is safe to remove now.
|
✔️ [V2] 🔨 Explore the source changes: 8065b89 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/61694f6c2128540008eb7c2a 😎 Browse the preview: https://deploy-preview-5709--docusaurus-2.netlify.app |
|
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5709--docusaurus-2.netlify.app/ |
|
Size Change: -46 B (0%) Total Size: 841 kB
ℹ️ View Unchanged
|
|
Didn't notice any issue 👍 |
Motivation
This PR tries to unify use of scroll handlers in
useScrollPosition, as there are quite a few non-obvious and unnecessary things right now. Beside that, it improves performance a bit, at least hideable navbar is no longer rendered twice on first mount.It also fixes proper closing of hideable navbar when navigating from search (eg, "docs/next/versioning#docs"):
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Preview. It's not that simple, you have to check hideable navbar and back-to-top-button.
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.)