fix(v2): fix FOUC in doc sidebar and various improvements #2867
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
CC @jsjoeio @lex111 @yangshun , this is a fix for #2682 (comment)
I investigated the reasons of the FOUC on the docs sidebar after adding the
category.collapsed = false
, but actually found multiple problems that lead me to this refactor (some of them existed before).Reading
window.location
to know which sidebar items are "active": that works only client-side after hydration, and was a reason of the FOUC. Replaced byactivePath
that's actually provided on both client and server (via ReactRouter ). Note it could have been possible to useuseLocation
from React-router as well.Bad normalization of the new category collapsed attribute. We want to ensure to always have a mandatory boolean for this setting in the metadata, otherwise we'll have to to
const collapsed = maybeCollapsed ?? true
everywhere.Non-recursive active sidebar item, which makes the
Guides
not being highlighted hereAfter this refactor, I think the
collapsed
feature works as intended and the code is cleaner than before.Please tell me if you see a breaking change or issue with existing behavior.