Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/routes/_library/charts.catalog.charts.$caseId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ export const Route = createFileRoute('/_library/charts/catalog/charts/$caseId')(

function ChartsCatalogCaseRoute() {
const data = Route.useLoaderData()
// Loader data can be briefly undefined during client navigation; show the
// pending UI instead of crashing on `data.case`.
if (!data) return <ChartsCatalogDetailPending />
return <ChartsCatalogDetail catalogCase={data.case} />
}
29 changes: 29 additions & 0 deletions tests/charts-catalog-case-route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { test } from 'node:test'

const routeSource = readFileSync(
new URL(
'../src/routes/_library/charts.catalog.charts.$caseId.tsx',
import.meta.url,
),
'utf8',
)

test('charts catalog case route guards undefined loader data before reading case', () => {
const component = routeSource.slice(
routeSource.indexOf('function ChartsCatalogCaseRoute'),
)
const guardIndex = component.indexOf(
'if (!data) return <ChartsCatalogDetailPending />',
)
const caseIndex = component.indexOf('catalogCase={data.case}')
assert.ok(
guardIndex !== -1,
'expected a pending fallback when loader data is undefined',
)
assert.ok(
guardIndex < caseIndex,
'guard must run before data.case is accessed',
)
})
Loading