Skip to content

Commit cacce07

Browse files
committed
fix(settings): handle unavailable pathname
1 parent 261149d commit cacce07

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

apps/sim/components/settings/settings-intent-link.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { act, type ComponentProps } from 'react'
55
import { createRoot, type Root } from 'react-dom/client'
66
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
77

8-
const { mockPathname } = vi.hoisted(() => ({ mockPathname: vi.fn(() => '/settings/billing') }))
8+
const { mockPathname } = vi.hoisted(() => ({
9+
mockPathname: vi.fn<() => string | null>(() => '/settings/billing'),
10+
}))
911

1012
vi.mock('next/navigation', () => ({ usePathname: mockPathname }))
1113
vi.mock('next/link', () => ({
@@ -181,4 +183,13 @@ describe('SettingsIntentLink', () => {
181183
expect(link).toHaveAttribute('data-prefetch', 'false')
182184
expect(onIntent).not.toHaveBeenCalled()
183185
})
186+
187+
it('renders before the pathname is available', () => {
188+
mockPathname.mockReturnValue(null)
189+
190+
const { link } = renderLink()
191+
192+
expect(link).toHaveAttribute('href', '/settings/general')
193+
expect(link).toHaveAttribute('data-prefetch', 'false')
194+
})
184195
})

apps/sim/components/settings/settings-intent-link.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function SettingsIntentLink(props: SettingsIntentLinkProps) {
3939
const destinationPathname = hrefPathname(props.href)
4040
const isCurrentRoute =
4141
destinationPathname !== null &&
42+
pathname !== null &&
4243
(destinationPathname === pathname || pathname.startsWith(`${destinationPathname}/`))
4344
const routeRole = isCurrentRoute ? 'current' : 'destination'
4445

0 commit comments

Comments
 (0)