-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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): fix FOUC in doc sidebar and various improvements #2867
Conversation
…ave a boolean after normalization
Deploy preview for docusaurus-2 ready! Built with commit a3d7517 |
@@ -9,30 +9,25 @@ module.exports = { | |||
docs: [ | |||
{ | |||
type: 'category', | |||
collapsed: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed on purpose, to test that the normalization process actually fallbacks to true
); | ||
} | ||
return false; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can detect active items with infinite category levels
sidebarData.forEach((sidebarItem) => | ||
mutateSidebarCollapsingState(sidebarItem, path), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very dangerous, particularly on the server, as mutating any object of sidebarData would affect other pages rendering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the sidebarCollapsible
option (when sidebarCollapsible = false
) became broken after this refactoring.
Current | Should be |
---|---|
thanks @lex111 that should be fixed now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! 👏
thanks :) |
Wow! You're so quick. Fantastic work @slorber - thank you for cleaning up the small mess I made 😜 but seriously, you rock! 💯 |
thanks 😃 |
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.