-
Notifications
You must be signed in to change notification settings - Fork 5.4k
refactor: nav to server component; add loading states #15642
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6b3c7e2
refactor: nav menu to ssr
wackerow 1e8093c
styling: reduce skeleton default opacity
wackerow de4d297
refactor: simplify dom and organize hooks
wackerow 2bddfae
Merge branch 'dev' into nav-ssr-loading
wackerow 6238c41
fix: story prop
wackerow ad3b400
Merge branch 'dev' into nav-ssr-loading
wackerow 4452b70
Merge branch 'dev' into nav-ssr-loading
wackerow 792a8f7
design: update skeleton shade default
wackerow dd7fae3
chore: remove unused conditional
wackerow f3ccf83
polish: adjust nav skeleton opacity and sizing
wackerow 2b382f9
refactor: use await getLocale
wackerow 2087e12
polish: loading components pixel placement
wackerow fa6cf03
revert: locale prop in story
wackerow 9423cf0
feat: add slow-pulse variant to ui/skeleton
wackerow aab7049
design: use slow-pulse and fade-in for nav lazy loads
wackerow 9e96afb
patch: opacity
wackerow 8c084a3
revert: slow-pulse
wackerow 7ab5398
fix: fade-in animation class name
wackerow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| "use client" | ||
|
|
||
| import { useParams } from "next/navigation" | ||
|
|
||
| import { cn } from "@/lib/utils/cn" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| "use client" | ||
|
|
||
| import { useRef } from "react" | ||
| import dynamic from "next/dynamic" | ||
| import { useLocale } from "next-intl" | ||
| import { BsTranslate } from "react-icons/bs" | ||
|
|
||
| import SearchButton from "@/components/Search/SearchButton" | ||
| import SearchInputButton from "@/components/Search/SearchInputButton" | ||
| import { Button } from "@/components/ui/buttons/Button" | ||
| import { Skeleton } from "@/components/ui/skeleton" | ||
|
|
||
| import { DESKTOP_LANGUAGE_BUTTON_NAME } from "@/lib/constants" | ||
|
|
||
| import { useNavigation } from "../useNavigation" | ||
| import { useThemeToggle } from "../useThemeToggle" | ||
|
|
||
| import { useBreakpointValue } from "@/hooks/useBreakpointValue" | ||
| import { useTranslation } from "@/hooks/useTranslation" | ||
|
|
||
| const Menu = dynamic(() => import("../Menu"), { | ||
| ssr: false, | ||
| loading: () => ( | ||
| <div className="me-8 flex w-full items-center gap-10 px-6 max-md:hidden"> | ||
| {Array.from({ length: 5 }).map((_, i) => ( | ||
| <Skeleton key={i} className="h-6 w-12 py-2" /> | ||
| ))} | ||
| </div> | ||
| ), | ||
| }) | ||
|
|
||
| const MobileMenuLoading = () => ( | ||
| <Skeleton data-label="mobile-menu" className="ms-2 size-6" /> | ||
| ) | ||
|
|
||
| const MobileNavMenu = dynamic(() => import("../Mobile"), { | ||
| ssr: false, | ||
| loading: MobileMenuLoading, | ||
| }) | ||
|
|
||
| const SearchProvider = dynamic(() => import("../../Search"), { | ||
| ssr: false, | ||
| loading: () => ( | ||
| <> | ||
| <div className="flex items-center gap-6 px-2 max-md:hidden xl:px-3"> | ||
| <Skeleton | ||
| data-label="search-xl" | ||
| className="hidden h-6 w-[169px] xl:flex" | ||
| /> | ||
| <Skeleton data-label="search" className="size-6 xl:hidden" /> | ||
| </div> | ||
| <div className="flex items-center md:hidden"> | ||
| <Skeleton data-label="search" className="mx-2 size-6" /> | ||
| <MobileMenuLoading /> | ||
| </div> | ||
| </> | ||
| ), | ||
| }) | ||
|
|
||
| const LanguagePicker = dynamic(() => import("../../LanguagePicker"), { | ||
| ssr: false, | ||
| loading: () => ( | ||
| // LG skeleton width approximates English "[icon] Languages EN" text width | ||
| <Skeleton className="h-6 max-md:hidden md:mx-2 md:w-[54px] lg:mx-3 lg:w-[8.875rem]" /> | ||
| ), | ||
| }) | ||
|
|
||
| const ClientSideNav = () => { | ||
| const { t } = useTranslation("common") | ||
| const locale = useLocale() | ||
|
|
||
| const { linkSections } = useNavigation() | ||
| const { toggleColorMode, ThemeIcon, themeIconAriaLabel } = useThemeToggle() | ||
|
|
||
| const languagePickerRef = useRef<HTMLButtonElement>(null) | ||
|
|
||
| // avoid rendering/adding desktop Menu version to DOM on mobile | ||
| const desktopScreen = useBreakpointValue({ base: false, md: true }) | ||
|
|
||
| return ( | ||
| <> | ||
| {desktopScreen && ( | ||
| <Menu | ||
| className="animate-fade-in max-md:hidden" | ||
| sections={linkSections} | ||
| /> | ||
| )} | ||
|
|
||
| <div className="flex items-center"> | ||
| <SearchProvider> | ||
| {({ onOpen }) => { | ||
| return ( | ||
| <> | ||
| <SearchInputButton | ||
| className="animate-fade-in max-xl:hidden" | ||
| onClick={onOpen} | ||
| /> | ||
| <SearchButton | ||
| className="animate-fade-in xl:hidden" | ||
| onClick={onOpen} | ||
| /> | ||
|
|
||
| {!desktopScreen && ( | ||
| <MobileNavMenu | ||
| toggleColorMode={toggleColorMode} | ||
| linkSections={linkSections} | ||
| toggleSearch={onOpen} | ||
| className="flex animate-fade-in md:hidden" | ||
| /> | ||
| )} | ||
| </> | ||
| ) | ||
| }} | ||
| </SearchProvider> | ||
|
|
||
| {desktopScreen && ( | ||
| <Button | ||
|
Member
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. I think we also need to display a skeleton for this button. Currently, the button is no responsive when clicked in pre-load time, affecting INP and FID. We can tackle this is a separate PR. |
||
| aria-label={themeIconAriaLabel} | ||
| variant="ghost" | ||
| isSecondary | ||
| className="group animate-fade-in px-2 max-md:hidden xl:px-3 [&>svg]:transition-transform [&>svg]:duration-500 [&>svg]:hover:rotate-12 [&>svg]:hover:text-primary-hover" | ||
| onClick={toggleColorMode} | ||
| > | ||
| <ThemeIcon className="transform-transform duration-500 group-hover:rotate-12 group-hover:transition-transform group-hover:duration-500" /> | ||
| </Button> | ||
| )} | ||
|
|
||
| {desktopScreen && ( | ||
| <LanguagePicker className="max-md:hidden"> | ||
| <Button | ||
| name={DESKTOP_LANGUAGE_BUTTON_NAME} | ||
| ref={languagePickerRef} | ||
| variant="ghost" | ||
| className="animate-fade-in gap-0 px-2 text-body transition-transform duration-500 active:bg-primary-low-contrast active:text-primary-hover data-[state='open']:bg-primary-low-contrast data-[state='open']:text-primary-hover max-md:hidden xl:px-3 [&_svg]:transition-transform [&_svg]:duration-500 [&_svg]:hover:rotate-12" | ||
| > | ||
| <BsTranslate className="me-2 align-middle text-2xl" /> | ||
| <span className="max-lg:hidden">{t("languages")} </span> | ||
| {locale!.toUpperCase()} | ||
| </Button> | ||
| </LanguagePicker> | ||
| )} | ||
| </div> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| ClientSideNav.displayName = "ClientSideNav" | ||
|
|
||
| export default ClientSideNav | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| "use client" | ||
|
|
||
| import { BaseHTMLAttributes } from "react" | ||
| import { motion } from "framer-motion" | ||
| import { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.