Skip to content

Commit a677d8d

Browse files
committed
fix(home): preserve ?home param in nav links during session pending state
1 parent 9b5d681 commit a677d8d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

apps/sim/app/(home)/components/navbar/navbar.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useCallback, useEffect, useRef, useState } from 'react'
44
import Image from 'next/image'
55
import Link from 'next/link'
6+
import { useSearchParams } from 'next/navigation'
67
import { GithubOutlineIcon } from '@/components/icons'
78
import { useSession } from '@/lib/auth/auth-client'
89
import { cn } from '@/lib/core/utils/cn'
@@ -41,9 +42,12 @@ interface NavbarProps {
4142

4243
export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps) {
4344
const brand = getBrandConfig()
45+
const searchParams = useSearchParams()
4446
const { data: session, isPending: isSessionPending } = useSession()
4547
const isAuthenticated = Boolean(session?.user?.id)
46-
const logoHref = isAuthenticated ? '/?home' : '/'
48+
const isBrowsingHome = searchParams.has('home')
49+
const useHomeLinks = isAuthenticated || isBrowsingHome
50+
const logoHref = useHomeLinks ? '/?home' : '/'
4751
const [activeDropdown, setActiveDropdown] = useState<DropdownId>(null)
4852
const [hoveredLink, setHoveredLink] = useState<string | null>(null)
4953
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
@@ -127,7 +131,7 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps
127131
<ul className='mt-[0.75px] hidden lg:flex'>
128132
{NAV_LINKS.map(({ label, href: rawHref, external, icon, dropdown }) => {
129133
const href =
130-
isAuthenticated && rawHref.startsWith('/#') ? `/?home${rawHref.slice(1)}` : rawHref
134+
useHomeLinks && rawHref.startsWith('/#') ? `/?home${rawHref.slice(1)}` : rawHref
131135
const hasDropdown = !!dropdown
132136
const isActive = hasDropdown && activeDropdown === dropdown
133137
const isThisHovered = hoveredLink === label
@@ -267,7 +271,7 @@ export default function Navbar({ logoOnly = false, blogPosts = [] }: NavbarProps
267271
<ul className='flex flex-col'>
268272
{NAV_LINKS.map(({ label, href: rawHref, external }) => {
269273
const href =
270-
isAuthenticated && rawHref.startsWith('/#')
274+
useHomeLinks && rawHref.startsWith('/#')
271275
? `/?home${rawHref.slice(1)}`
272276
: rawHref
273277
return (

apps/sim/app/(landing)/components/nav/nav.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createLogger } from '@sim/logger'
55
import { ArrowRight, ChevronRight } from 'lucide-react'
66
import Image from 'next/image'
77
import Link from 'next/link'
8-
import { useRouter } from 'next/navigation'
8+
import { useRouter, useSearchParams } from 'next/navigation'
99
import { GithubIcon } from '@/components/icons'
1010
import { useSession } from '@/lib/auth/auth-client'
1111
import { isHosted } from '@/lib/core/config/feature-flags'
@@ -27,9 +27,12 @@ export default function Nav({ hideAuthButtons = false, variant = 'landing' }: Na
2727
const router = useRouter()
2828
const brand = useBrandConfig()
2929
const buttonClass = useBrandedButtonClass()
30+
const searchParams = useSearchParams()
3031
const { data: session, isPending: isSessionPending } = useSession()
3132
const isAuthenticated = Boolean(session?.user?.id)
32-
const logoHref = isAuthenticated ? '/?home' : '/'
33+
const isBrowsingHome = searchParams.has('home')
34+
const useHomeLinks = isAuthenticated || isBrowsingHome
35+
const logoHref = useHomeLinks ? '/?home' : '/'
3336

3437
useEffect(() => {
3538
if (variant !== 'landing') return
@@ -76,7 +79,7 @@ export default function Nav({ hideAuthButtons = false, variant = 'landing' }: Na
7679
</li>
7780
<li>
7881
<Link
79-
href={isAuthenticated ? '/?home#pricing' : '/#pricing'}
82+
href={useHomeLinks ? '/?home#pricing' : '/#pricing'}
8083
className='text-[16px] text-muted-foreground transition-colors hover:text-foreground'
8184
scroll={true}
8285
>

0 commit comments

Comments
 (0)