{"version":3,"sources":["../../../../src/client/components/navigation.ts"],"sourcesContent":["import type { Params } from '../../server/request/params'\n\nimport React, { useContext, useMemo, use } from 'react'\nimport {\n  AppRouterContext,\n  LayoutRouterContext,\n  type AppRouterInstance,\n} from '../../shared/lib/app-router-context.shared-runtime'\nimport {\n  SearchParamsContext,\n  PathnameContext,\n  PathParamsContext,\n  NavigationPromisesContext,\n  ReadonlyURLSearchParams,\n} from '../../shared/lib/hooks-client-context.shared-runtime'\nimport {\n  computeSelectedLayoutSegment,\n  getSelectedLayoutSegmentPath,\n} from '../../shared/lib/segment'\n\nimport {\n  useDynamicRouteParams,\n  useDynamicSearchParams,\n} from './navigation-dynamic-rendering'\n\nconst {\n  instrumentParamsForClientValidation,\n  instrumentSearchParamsForClientValidation,\n  expectCompleteParamsInClientValidation,\n} = process.env.__NEXT_CACHE_COMPONENTS\n  ? (require('./instant-samples') as typeof import('./instant-samples'))\n  : {}\n\n/**\n * A [Client Component](https://nextjs.org/docs/app/building-your-application/rendering/client-components) hook\n * that lets you *read* the current URL's search parameters.\n *\n * Learn more about [`URLSearchParams` on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams)\n *\n * @example\n * ```ts\n * \"use client\"\n * import { useSearchParams } from 'next/navigation'\n *\n * export default function Page() {\n *   const searchParams = useSearchParams()\n *   searchParams.get('foo') // returns 'bar' when ?foo=bar\n *   // ...\n * }\n * ```\n *\n * Read more: [Next.js Docs: `useSearchParams`](https://nextjs.org/docs/app/api-reference/functions/use-search-params)\n */\n// Client components API\nexport function useSearchParams(): ReadonlyURLSearchParams {\n  useDynamicSearchParams?.('useSearchParams()')\n\n  const searchParams = useContext(SearchParamsContext)\n\n  // In the case where this is `null`, the compat types added in\n  // `next-env.d.ts` will add a new overload that changes the return type to\n  // include `null`.\n  const readonlySearchParams = useMemo((): ReadonlyURLSearchParams => {\n    if (!searchParams) {\n      // When the router is not ready in pages, we won't have the search params\n      // available.\n      return null!\n    }\n\n    return new ReadonlyURLSearchParams(searchParams)\n  }, [searchParams])\n\n  // During build-time instant validation, wrap with an proxy\n  // so that accessing undeclared search params throws an error.\n  if (\n    typeof window === 'undefined' &&\n    process.env.__NEXT_CACHE_COMPONENTS &&\n    readonlySearchParams\n  ) {\n    return instrumentSearchParamsForClientValidation!(readonlySearchParams)\n  }\n\n  // Instrument with Suspense DevTools (dev-only)\n  if (process.env.NODE_ENV !== 'production' && 'use' in React) {\n    const navigationPromises = use(NavigationPromisesContext)\n    if (navigationPromises) {\n      return use(navigationPromises.searchParams)\n    }\n  }\n\n  return readonlySearchParams\n}\n\n/**\n * A [Client Component](https://nextjs.org/docs/app/building-your-application/rendering/client-components) hook\n * that lets you read the current URL's pathname.\n *\n * @example\n * ```ts\n * \"use client\"\n * import { usePathname } from 'next/navigation'\n *\n * export default function Page() {\n *  const pathname = usePathname() // returns \"/dashboard\" on /dashboard?foo=bar\n *  // ...\n * }\n * ```\n *\n * Read more: [Next.js Docs: `usePathname`](https://nextjs.org/docs/app/api-reference/functions/use-pathname)\n */\n// Client components API\nexport function usePathname(): string {\n  useDynamicRouteParams?.('usePathname()')\n\n  // In the case where this is `null`, the compat types added in `next-env.d.ts`\n  // will add a new overload that changes the return type to include `null`.\n  const pathname = useContext(PathnameContext) as string\n\n  // During build-time instant validation, error if fallback params exist\n  // because usePathname() can't return a sensible value without all params.\n  if (\n    typeof window === 'undefined' &&\n    process.env.__NEXT_CACHE_COMPONENTS &&\n    pathname\n  ) {\n    expectCompleteParamsInClientValidation!('usePathname()')\n    return pathname\n  }\n\n  // Instrument with Suspense DevTools (dev-only)\n  if (process.env.NODE_ENV !== 'production' && 'use' in React) {\n    const navigationPromises = use(NavigationPromisesContext)\n    if (navigationPromises) {\n      return use(navigationPromises.pathname)\n    }\n  }\n\n  return pathname\n}\n\n// Client components API\nexport {\n  ServerInsertedHTMLContext,\n  useServerInsertedHTML,\n} from '../../shared/lib/server-inserted-html.shared-runtime'\n\n/**\n *\n * This hook allows you to programmatically change routes inside [Client Component](https://nextjs.org/docs/app/building-your-application/rendering/client-components).\n *\n * @example\n * ```ts\n * \"use client\"\n * import { useRouter } from 'next/navigation'\n *\n * export default function Page() {\n *  const router = useRouter()\n *  // ...\n *  router.push('/dashboard') // Navigate to /dashboard\n * }\n * ```\n *\n * Read more: [Next.js Docs: `useRouter`](https://nextjs.org/docs/app/api-reference/functions/use-router)\n */\n// Client components API\nexport function useRouter(): AppRouterInstance {\n  const router = useContext(AppRouterContext)\n  if (router === null) {\n    throw new Error('invariant expected app router to be mounted')\n  }\n\n  // Read the bfcacheId of the closest CacheNode and merge it into the\n  // returned router instance. This is contextual: callers in a shared\n  // layout get the layout's id; callers in a leaf segment get the leaf's.\n  // The id is stored on the CacheNode as a number and materialized as a\n  // string here. The format mirrors React's `useId()` (e.g. `_r_0_`) with\n  // a `b` prefix, so the id can be safely concatenated with other keys\n  // without collision.\n  const layout = useContext(LayoutRouterContext)\n  const bfcacheIdNumber = layout?.parentCacheNode.bfcacheId ?? 0\n  return useMemo<AppRouterInstance>(\n    () => ({\n      back: router.back,\n      forward: router.forward,\n      refresh: router.refresh,\n      hmrRefresh: router.hmrRefresh,\n      push: router.push,\n      replace: router.replace,\n      prefetch: router.prefetch,\n      experimental_gesturePush: router.experimental_gesturePush,\n      bfcacheId: '_b_' + bfcacheIdNumber + '_',\n    }),\n    [router, bfcacheIdNumber]\n  )\n}\n\n/**\n * A [Client Component](https://nextjs.org/docs/app/building-your-application/rendering/client-components) hook\n * that lets you read a route's dynamic params filled in by the current URL.\n *\n * @example\n * ```ts\n * \"use client\"\n * import { useParams } from 'next/navigation'\n *\n * export default function Page() {\n *   // on /dashboard/[team] where pathname is /dashboard/nextjs\n *   const { team } = useParams() // team === \"nextjs\"\n * }\n * ```\n *\n * Read more: [Next.js Docs: `useParams`](https://nextjs.org/docs/app/api-reference/functions/use-params)\n */\n// Client components API\nexport function useParams<T extends Params = Params>(): T {\n  useDynamicRouteParams?.('useParams()')\n\n  const params = useContext(PathParamsContext) as T\n\n  // During build-time instant validation, wrap with a proxy\n  // so that accessing undeclared params throws an error.\n  if (\n    typeof window === 'undefined' &&\n    process.env.__NEXT_CACHE_COMPONENTS &&\n    params\n  ) {\n    return instrumentParamsForClientValidation!(params)\n  }\n\n  // Instrument with Suspense DevTools (dev-only)\n  if (process.env.NODE_ENV !== 'production' && 'use' in React) {\n    const navigationPromises = use(NavigationPromisesContext)\n    if (navigationPromises) {\n      return use(navigationPromises.params) as T\n    }\n  }\n\n  return params\n}\n\n/**\n * A [Client Component](https://nextjs.org/docs/app/building-your-application/rendering/client-components) hook\n * that lets you read the active route segments **below** the Layout it is called from.\n *\n * @example\n * ```ts\n * 'use client'\n *\n * import { useSelectedLayoutSegments } from 'next/navigation'\n *\n * export default function ExampleClientComponent() {\n *   const segments = useSelectedLayoutSegments()\n *\n *   return (\n *     <ul>\n *       {segments.map((segment, index) => (\n *         <li key={index}>{segment}</li>\n *       ))}\n *     </ul>\n *   )\n * }\n * ```\n *\n * Read more: [Next.js Docs: `useSelectedLayoutSegments`](https://nextjs.org/docs/app/api-reference/functions/use-selected-layout-segments)\n */\n// Client components API\nexport function useSelectedLayoutSegments(\n  parallelRouteKey: string = 'children'\n): string[] {\n  useDynamicRouteParams?.('useSelectedLayoutSegments()')\n\n  const context = useContext(LayoutRouterContext)\n  // @ts-expect-error This only happens in `pages`. Type is overwritten in navigation.d.ts\n  if (!context) return null\n\n  // During build-time instant validation, error if fallback params exist\n  // because useSelectedLayoutSegments() can't return a sensible value without all params.\n  if (\n    typeof window === 'undefined' &&\n    process.env.__NEXT_CACHE_COMPONENTS &&\n    context\n  ) {\n    expectCompleteParamsInClientValidation!('useSelectedLayoutSegments()')\n  }\n\n  // Instrument with Suspense DevTools (dev-only)\n  if (process.env.NODE_ENV !== 'production' && 'use' in React) {\n    const navigationPromises = use(NavigationPromisesContext)\n    if (navigationPromises) {\n      const promise =\n        navigationPromises.selectedLayoutSegmentsPromises?.get(parallelRouteKey)\n      if (promise) {\n        // We should always have a promise here, but if we don't, it's not worth erroring over.\n        // We just won't be able to instrument it, but can still provide the value.\n        return use(promise)\n      }\n    }\n  }\n\n  return getSelectedLayoutSegmentPath(context.parentTree, parallelRouteKey)\n}\n\n/**\n * A [Client Component](https://nextjs.org/docs/app/building-your-application/rendering/client-components) hook\n * that lets you read the active route segment **one level below** the Layout it is called from.\n *\n * @example\n * ```ts\n * 'use client'\n * import { useSelectedLayoutSegment } from 'next/navigation'\n *\n * export default function ExampleClientComponent() {\n *   const segment = useSelectedLayoutSegment()\n *\n *   return <p>Active segment: {segment}</p>\n * }\n * ```\n *\n * Read more: [Next.js Docs: `useSelectedLayoutSegment`](https://nextjs.org/docs/app/api-reference/functions/use-selected-layout-segment)\n */\n// Client components API\nexport function useSelectedLayoutSegment(\n  parallelRouteKey: string = 'children'\n): string | null {\n  useDynamicRouteParams?.('useSelectedLayoutSegment()')\n  const navigationPromises = useContext(NavigationPromisesContext)\n  const selectedLayoutSegments = useSelectedLayoutSegments(parallelRouteKey)\n\n  // During build-time instant validation, error if fallback params exist\n  // because useSelectedLayoutSegment() can't return a sensible value without all params.\n  if (typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS) {\n    expectCompleteParamsInClientValidation!('useSelectedLayoutSegment()')\n  }\n\n  // Instrument with Suspense DevTools (dev-only)\n  if (\n    process.env.NODE_ENV !== 'production' &&\n    navigationPromises &&\n    'use' in React\n  ) {\n    const promise =\n      navigationPromises.selectedLayoutSegmentPromises?.get(parallelRouteKey)\n    if (promise) {\n      // We should always have a promise here, but if we don't, it's not worth erroring over.\n      // We just won't be able to instrument it, but can still provide the value.\n      return use(promise)\n    }\n  }\n\n  return computeSelectedLayoutSegment(selectedLayoutSegments, parallelRouteKey)\n}\n\nexport { unstable_isUnrecognizedActionError } from './unrecognized-action-error'\n\n// Shared components APIs\nexport {\n  // We need the same class that was used to instantiate the context value\n  // Otherwise instanceof checks will fail in usercode\n  ReadonlyURLSearchParams,\n}\nexport {\n  notFound,\n  forbidden,\n  unauthorized,\n  redirect,\n  permanentRedirect,\n  RedirectType,\n  unstable_rethrow,\n} from './navigation.react-server'\n"],"names":["React","useContext","useMemo","use","AppRouterContext","LayoutRouterContext","SearchParamsContext","PathnameContext","PathParamsContext","NavigationPromisesContext","ReadonlyURLSearchParams","computeSelectedLayoutSegment","getSelectedLayoutSegmentPath","useDynamicRouteParams","useDynamicSearchParams","instrumentParamsForClientValidation","instrumentSearchParamsForClientValidation","expectCompleteParamsInClientValidation","process","env","__NEXT_CACHE_COMPONENTS","require","useSearchParams","searchParams","readonlySearchParams","window","NODE_ENV","navigationPromises","usePathname","pathname","ServerInsertedHTMLContext","useServerInsertedHTML","useRouter","router","Error","layout","bfcacheIdNumber","parentCacheNode","bfcacheId","back","forward","refresh","hmrRefresh","push","replace","prefetch","experimental_gesturePush","useParams","params","useSelectedLayoutSegments","parallelRouteKey","context","promise","selectedLayoutSegmentsPromises","get","parentTree","useSelectedLayoutSegment","selectedLayoutSegments","selectedLayoutSegmentPromises","unstable_isUnrecognizedActionError","notFound","forbidden","unauthorized","redirect","permanentRedirect","RedirectType","unstable_rethrow"],"mappings":"AAEA,OAAOA,SAASC,UAAU,EAAEC,OAAO,EAAEC,GAAG,QAAQ,QAAO;AACvD,SACEC,gBAAgB,EAChBC,mBAAmB,QAEd,qDAAoD;AAC3D,SACEC,mBAAmB,EACnBC,eAAe,EACfC,iBAAiB,EACjBC,yBAAyB,EACzBC,uBAAuB,QAClB,uDAAsD;AAC7D,SACEC,4BAA4B,EAC5BC,4BAA4B,QACvB,2BAA0B;AAEjC,SACEC,qBAAqB,EACrBC,sBAAsB,QACjB,iCAAgC;AAEvC,MAAM,EACJC,mCAAmC,EACnCC,yCAAyC,EACzCC,sCAAsC,EACvC,GAAGC,QAAQC,GAAG,CAACC,uBAAuB,GAClCC,QAAQ,uBACT,CAAC;AAEL;;;;;;;;;;;;;;;;;;;CAmBC,GACD,wBAAwB;AACxB,OAAO,SAASC;IACdR,yBAAyB;IAEzB,MAAMS,eAAet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