Quest for Codev2.0.0
/
SIGN IN
next.js/test/e2e/app-dir/instant-validation-build/app/(default)/search-params/invalid-undeclared-search-param/page.tsx
page.tsx34 lines835 B
import { ensureThrows } from '../../../../ensure-error'

export const unstable_instant = { samples: [{ searchParams: { q: 'test' } }] }
export const unstable_prefetch = 'force-runtime'

export default async function Page({
  searchParams,
}: {
  searchParams: Promise<{ q?: string; undeclared?: string }>
}) {
  return (
    <main>
      <p>
        This page reads a searchParam that is not declared in the sample, so it
        should fail validation with an exhaustiveness error.
      </p>
      <SearchResult searchParams={searchParams} />
    </main>
  )
}

async function SearchResult({
  searchParams,
}: {
  searchParams: Promise<{ q?: string; undeclared?: string }>
}) {
  const sp = await searchParams
  ensureThrows(
    () => sp.undeclared,
    `Expected accessing an undeclared search param to throw`
  )
  return null
}