{"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":["ReadonlyURLSearchParams","RedirectType","ServerInsertedHTMLContext","forbidden","notFound","permanentRedirect","redirect","unauthorized","unstable_isUnrecognizedActionError","unstable_rethrow","useParams","usePathname","useRouter","useSearchParams","useSelectedLayoutSegment","useSelectedLayoutSegments","useServerInsertedHTML","instrumentParamsForClientValidation","instrumentSearchParamsForClientValidation","expectCompleteParamsInClientValidation","process","env","__NEXT_CACHE_COMPONENTS","require","useDynamicSearchParams","searchParams","useContext","SearchParamsContext","readonlySearchParams","useMemo","window","NODE_ENV","React","navigationPromises","use","NavigationPromisesContext","useDynamicRouteParams","pathname","PathnameContext","router","AppRouterContext","Error","layout","LayoutRouterContext","bfcacheIdNumber","parentCacheNode","bfcacheId","back","forward","refresh","hmrRefresh","push","replace","prefetch","experimental_gesturePush","params","PathParamsContext","parallelRouteKey","context","promise","selectedLayoutSegmentsPromises","get","getSelectedLayoutSegmentPath","parentTree","selectedLayoutSegments","selectedLayoutSegmentPromises","computeSelectedLayoutSegment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoWE,wEAAwE;IACxE,oDAAoD;IACpDA,uBAAuB;eAAvBA,wDAAuB;;IAQvBC,YAAY;eAAZA,mCAAY;;IAhOZC,yBAAyB;eAAzBA,0DAAyB;;IA4NzBC,SAAS;eAATA,gCAAS;;IADTC,QAAQ;eAARA,+BAAQ;;IAIRC,iBAAiB;eAAjBA,wCAAiB;;IADjBC,QAAQ;eAARA,+BAAQ;;IADRC,YAAY;eAAZA,mCAAY;;IAXLC,kCAAkC;eAAlCA,2DAAkC;;IAezCC,gBAAgB;eAAhBA,uCAAgB;;IAzJFC,SAAS;eAATA;;IAvGAC,WAAW;eAAXA;;IAsDAC,SAAS;eAATA;;IA/GAC,eAAe;eAAfA;;IA2QAC,wBAAwB;eAAxBA;;IAvDAC,yBAAyB;eAAzBA;;IA3HdC,qBAAqB;eA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