Skip to content

Commit c5c5f3a

Browse files
Defer mobile navbar auth loading (#1110)
1 parent b3e98cc commit c5c5f3a

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

src/components/Navbar.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ export function Navbar({ children }: { children: React.ReactNode }) {
693693
<MobileNavigation
694694
key={mobileMenuOpen ? 'open' : 'closed'}
695695
activeKey={mobileMenuKey}
696+
loadAuthControls={mobileMenuOpen}
696697
onBack={() => setMobileMenuKey(null)}
697698
onNavigate={() => setMobileMenuOpen(false)}
698699
onOpenLibraries={() => {
@@ -836,12 +837,14 @@ function DesktopNavDropdown({
836837

837838
function MobileNavigation({
838839
activeKey,
840+
loadAuthControls,
839841
onBack,
840842
onNavigate,
841843
onOpenLibraries,
842844
onSelect,
843845
}: {
844846
activeKey: NavMenuKey | null
847+
loadAuthControls: boolean
845848
onBack: () => void
846849
onNavigate: () => void
847850
onOpenLibraries: () => void
@@ -859,6 +862,18 @@ function MobileNavigation({
859862
}
860863
}
861864

865+
const signIn = (
866+
<Link
867+
to="/login"
868+
tabIndex={activeGroup ? -1 : 0}
869+
onClick={onNavigate}
870+
className="flex w-full items-center gap-3.5 rounded-xl px-3 py-4 text-left font-ds-display text-ds-heading-3 text-[#a3a3a3] transition-colors hover:bg-[#171717] hover:text-white focus-visible:bg-[#171717] focus-visible:text-white focus-visible:outline-none"
871+
>
872+
<SignInIcon className="size-8 shrink-0" />
873+
Sign In
874+
</Link>
875+
)
876+
862877
return (
863878
<nav aria-label="Mobile navigation" className="overflow-hidden">
864879
<div
@@ -912,24 +927,16 @@ function MobileNavigation({
912927
<Sparkles className="size-8 shrink-0" />
913928
Ask AI
914929
</button>
915-
<React.Suspense
916-
fallback={
917-
<Link
918-
to="/login"
930+
{loadAuthControls ? (
931+
<React.Suspense fallback={signIn}>
932+
<LazyMobileNavbarAuthControls
919933
tabIndex={activeGroup ? -1 : 0}
920-
onClick={onNavigate}
921-
className="flex w-full items-center gap-3.5 rounded-xl px-3 py-4 text-left font-ds-display text-ds-heading-3 text-[#a3a3a3] transition-colors hover:bg-[#171717] hover:text-white focus-visible:bg-[#171717] focus-visible:text-white focus-visible:outline-none"
922-
>
923-
<SignInIcon className="size-8 shrink-0" />
924-
Sign In
925-
</Link>
926-
}
927-
>
928-
<LazyMobileNavbarAuthControls
929-
tabIndex={activeGroup ? -1 : 0}
930-
onNavigate={onNavigate}
931-
/>
932-
</React.Suspense>
934+
onNavigate={onNavigate}
935+
/>
936+
</React.Suspense>
937+
) : (
938+
signIn
939+
)}
933940
</div>
934941
</div>
935942

0 commit comments

Comments
 (0)