-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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: apply announcement bar class if only needed #5699
Conversation
@@ -32,8 +32,8 @@ const isDismissedInStorage = () => | |||
const setDismissedInStorage = (bool: boolean) => | |||
AnnouncementBarDismissStorage.set(String(bool)); | |||
|
|||
type AnnouncementBarAPI = { | |||
readonly isClosed: boolean; | |||
type AnnouncementBarAPI = AnnouncementBarConfig & { |
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.
I refactored the code a bit to collect data related with announcement bar in one place (context), and then use it in children components. It seems like it should be better and clearer, doesn't it?
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.
I'm not sure it's a good idea: we are mixing a global state + its mutable api with a global config, and it becomes less clear what attribute is part of global state/global config + can trigger additional useless re-renders on places that only need to read the global config (immutable)
@@ -87,8 +87,9 @@ const useAnnouncementBarContextValue = (): AnnouncementBarAPI => { | |||
|
|||
return useMemo(() => { | |||
return { | |||
isClosed, | |||
isActive: !!(announcementBar && announcementBar?.content) && !isClosed, |
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.
Honestly, I would remove content
part here, it's strange that someone will want render empty bar.
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.
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5699--docusaurus-2.netlify.app/ |
✔️ [V2] 🔨 Explore the source changes: 95e69d9 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/616711bd9aedc10007c282fe 😎 Browse the preview: https://deploy-preview-5699--docusaurus-2.netlify.app |
Size Change: +2 B (0%) Total Size: 837 kB ℹ️ View Unchanged
|
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.
Thanks
It seems to this fixes the issue, but not agreeing with all the changes
close: handleClose, | ||
...announcementBar, | ||
}; | ||
}, [isClosed]); |
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.
}, [isClosed]); | |
}, [isClosed, announcementBar]); |
deps used in useMemo should be added (even if in this case it does nothing): I'd like to add the eslint react deps plugin soon as we should rather follow those rules more strictly
@@ -87,8 +87,9 @@ const useAnnouncementBarContextValue = (): AnnouncementBarAPI => { | |||
|
|||
return useMemo(() => { | |||
return { | |||
isClosed, | |||
isActive: !!(announcementBar && announcementBar?.content) && !isClosed, |
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.
@@ -49,11 +49,11 @@ export type ColorModeConfig = { | |||
}; | |||
|
|||
export type AnnouncementBarConfig = { |
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.
don't agree with those ?
: these must match the validation logic.
If a field is required or has a default, it shouldn't be `? (id, isCloseable and content)
@@ -32,8 +32,8 @@ const isDismissedInStorage = () => | |||
const setDismissedInStorage = (bool: boolean) => | |||
AnnouncementBarDismissStorage.set(String(bool)); | |||
|
|||
type AnnouncementBarAPI = { | |||
readonly isClosed: boolean; | |||
type AnnouncementBarAPI = AnnouncementBarConfig & { |
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.
I'm not sure it's a good idea: we are mixing a global state + its mutable api with a global config, and it becomes less clear what attribute is part of global state/global config + can trigger additional useless re-renders on places that only need to read the global config (immutable)
@@ -25,14 +25,16 @@ import type {Props} from '@theme/DocSidebar'; | |||
import styles from './styles.module.css'; | |||
|
|||
function useShowAnnouncementBar() { |
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.
I have a hard time understandig why this logic is only in DocSidebar, do you remember?
For me, the announcement bar should work the same on docs, blog or any page that displays the layout. Can't we remove this code?
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.
I understand there may be a CSS need regarding the sidebar height.
What I don't understand is why we only call setShowAnnouncementBar
on docs page. Is the boolean always false on the homepage?
Could we move this logic directly inside useAnnouncementBarContextValue
instead of DocSidebar
?
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.
I understand better.
An idea could be to use some JS to store the scrollY offset in a CSS var: we'd be able to use that CSS var in other places and also handle "intermediate" states where the announcementBar is partially visible
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.
This is pretty specific logic for just classic theme, so I would not move it to a common hook.
Fixed it all, should be fine this time. |
LGTM thanks |
Motivation
Currently, a "special" CSS class
menuWithAnnouncementBar
mistakenly applies to a sidebar menu even if announcement bar is not used.Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Remove
announcementBar
field from config file and inspect layout via dev tools.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.)