-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(banner): add x for closing (with prehydration)
#9009
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
Changes from all commits
b70b8ab
bd140ea
b2dc64f
dc9e701
f2f736b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| 'use client'; | ||
|
|
||
| import { ArrowUpRightIcon } from '@heroicons/react/24/outline'; | ||
| import Banner from '@node-core/ui-components/Common/Banner'; | ||
| import { useTranslations } from 'next-intl'; | ||
| import { useEffect, useState } from 'react'; | ||
|
|
||
| import Link from '#site/components/Link'; | ||
| import { siteConfig } from '#site/next.json.mjs'; | ||
| import { BANNER_DISMISSAL_STORAGE_KEY } from '#site/util/banner'; | ||
| import { dateIsBetween } from '#site/util/date'; | ||
|
|
||
| import type { FC } from 'react'; | ||
|
|
@@ -12,13 +16,32 @@ | |
| const banner = siteConfig.websiteBanners[section]; | ||
| const t = useTranslations(); | ||
|
|
||
| if (banner && dateIsBetween(banner.startDate, banner.endDate)) { | ||
| const [dismissed, setDismissed] = useState(false); | ||
|
|
||
| // The pre-hydration script hides a dismissed banner before the first paint. | ||
| // This effect then synchronizes that state with React after hydration. | ||
| useEffect(() => { | ||
| if (banner) { | ||
| setDismissed( | ||
| localStorage.getItem(BANNER_DISMISSAL_STORAGE_KEY) === banner.text | ||
| ); | ||
| } | ||
| }, [banner]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dismissed banner flashes on remountMedium Severity After closing the banner in the same visit, client-side navigation that swaps page layouts remounts Additional Locations (1)Reviewed by Cursor Bugbot for commit dc9e701. Configure here. |
||
|
|
||
| if (banner && !dismissed && dateIsBetween(banner.startDate, banner.endDate)) { | ||
| const bannerType = banner.type || 'default'; | ||
|
|
||
| const onClose = () => { | ||
| localStorage.setItem(BANNER_DISMISSAL_STORAGE_KEY, banner.text); | ||
| setDismissed(true); | ||
| }; | ||
|
|
||
| return ( | ||
| <Banner | ||
| type={banner.type} | ||
| aria-label={t(`components.banner.${bannerType}`)} | ||
| data-dismissible-banner="" | ||
| onClose={onClose} | ||
| > | ||
| {banner.link ? ( | ||
| <Link href={banner.link}>{banner.text}</Link> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const BANNER_DISMISSAL_STORAGE_KEY = 'banner-dismissal'; |


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.
Yea... that's not happening