{"version":3,"file":"Match.cjs","names":[],"sources":["../../src/Match.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { isNotFound, rootRouteId } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { CatchNotFound } from './not-found'\nimport { matchContext } from './matchContext'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { ScrollRestoration } from './scroll-restoration'\nimport { ClientOnly } from './ClientOnly'\nimport {\n nonRouteComponentContext,\n wrapInNonRouteComponentContext,\n} from './nonRouteComponentContext'\nimport type {\n AnyRoute,\n AnyRouteMatch,\n RootRouteOptions,\n} from '@tanstack/router-core'\n\nexport function renderPending(\n router: ReturnType,\n route?: AnyRoute,\n) {\n const PendingComponent =\n route?.options.pendingComponent ?? router.options.defaultPendingComponent\n if (!PendingComponent) {\n return null\n }\n\n const pendingElement = \n return process.env.NODE_ENV !== 'production'\n ? wrapInNonRouteComponentContext(pendingElement, 'pendingComponent')\n : pendingElement\n}\n\ntype OutletMatchSelection = [\n parentGlobalNotFound: boolean,\n parentNotFoundError: unknown,\n]\n\nconst outletMatchSelectionEqual = (\n a: OutletMatchSelection,\n b: OutletMatchSelection,\n) => a[0] === b[0] && a[1] === b[1]\n\nexport const Match = React.memo(function MatchImpl({\n routeId,\n}: {\n routeId: string\n}) {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n const match = router.stores.byRoute.get(routeId)!.get()!\n return \n }\n\n const matchStore = router.stores.getMatchStore(routeId)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n return \n})\n\nfunction MatchView({\n router,\n match,\n}: {\n router: ReturnType\n match: AnyRouteMatch\n}) {\n const route: AnyRoute = router.routesById[match.routeId]\n\n const pendingElement = renderPending(router, route)\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the _notFound option, with fallback to the notFoundRoute's component\n (route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component)\n : route.options.notFoundComponent\n\n const resolvedNoSsr = match.ssr === false || match.ssr === 'data-only'\n const ResolvedSuspenseBoundary =\n (route.options.wrapInSuspense ??\n pendingElement ??\n ((route.options.errorComponent as any)?.preload || resolvedNoSsr))\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const ShellComponent = route.isRoot\n ? ((route.options as RootRouteOptions).shellComponent ?? SafeFragment)\n : SafeFragment\n return (\n \n \n \n match}\n errorComponent={routeErrorComponent as any}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) {\n error.routeId ??= match.routeId\n throw error\n }\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Warning: Error in route match: ${match.id}`)\n }\n routeOnCatch?.(error, errorInfo)\n }}\n >\n {\n error.routeId ??= match.routeId\n\n if (error.routeId !== match.routeId) {\n throw error\n }\n\n const notFoundElement = React.createElement(\n routeNotFoundComponent!,\n error as any,\n )\n return process.env.NODE_ENV !== 'production'\n ? wrapInNonRouteComponentContext(\n notFoundElement,\n 'notFoundComponent',\n )\n : notFoundElement\n }}\n >\n {resolvedNoSsr ? (\n \n \n \n ) : (\n \n )}\n \n \n \n \n {(isServer ?? router.isServer) &&\n route.parentRoute?.id === rootRouteId &&\n router.options.scrollRestoration ? (\n \n ) : null}\n \n )\n}\n\nexport const MatchInner = React.memo(function MatchInnerImpl({\n match,\n}: {\n match: AnyRouteMatch\n}): any {\n const router = useRouter()\n const routeId = match.routeId\n const route = router.routesById[routeId] as AnyRoute\n const key = React.useMemo(() => {\n const remountFn =\n route.options.remountDeps ?? router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n return remountDeps ? JSON.stringify(remountDeps) : undefined\n }, [\n routeId,\n match.loaderDeps,\n match._strictParams,\n match._strictSearch,\n route.options.remountDeps,\n router.options.defaultRemountDeps,\n ])\n const out = React.useMemo(() => {\n const Comp = route.options.component ?? router.options.defaultComponent\n return Comp ? : \n }, [key, route.options.component, router.options.defaultComponent])\n\n if (match.status === 'pending') {\n if (router._tx) {\n throw router._tx[5]\n }\n return renderPending(router, route)\n }\n\n if (match.status === 'notFound') {\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'error') {\n if (isServer ?? router.isServer) {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n const errorElement = (\n \n )\n return process.env.NODE_ENV !== 'production'\n ? wrapInNonRouteComponentContext(errorElement, 'errorComponent')\n : errorElement\n }\n throw match.error\n }\n\n return out\n})\n\n/**\n * Render the next child match in the route tree. Typically used inside\n * a route component to render nested routes.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/outletComponent\n */\nexport const Outlet = React.memo(function OutletImpl() {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const nonRouteComponent = React.useContext(nonRouteComponentContext!)\n if (nonRouteComponent) {\n console.warn(\n `Warning: An was rendered inside a ${nonRouteComponent}. should only be rendered inside a route component.`,\n )\n }\n }\n\n const router = useRouter()\n const routeId = React.useContext(matchContext)!\n\n let parentGlobalNotFound: boolean\n let parentNotFoundError: unknown\n let childRouteId: string | undefined\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.matches.get()\n const parentIndex = matches.findIndex((match) => match.routeId === routeId)\n const parentMatch = matches[parentIndex]!\n parentGlobalNotFound = !!parentMatch._notFound\n parentNotFoundError = parentMatch.error\n childRouteId = matches[parentIndex + 1]?.routeId\n } else {\n const parentMatchStore = router.stores.getMatchStore(routeId)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n ;[parentGlobalNotFound, parentNotFoundError] = useStore(\n parentMatchStore,\n (match): OutletMatchSelection => [!!match!._notFound, match!.error],\n outletMatchSelectionEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n childRouteId = useStore(router.stores.ids, (ids) => {\n return ids[ids.indexOf(routeId) + 1]\n })\n }\n\n if (parentGlobalNotFound) {\n return renderRouteNotFound(\n router,\n router.routesById[routeId],\n parentNotFoundError,\n )\n }\n\n if (!childRouteId) {\n return null\n }\n\n const nextMatch = \n\n if (routeId === rootRouteId) {\n return (\n \n {nextMatch}\n \n )\n }\n\n return nextMatch\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,SAAgB,cACd,QACA,OACA;CACA,MAAM,mBACJ,OAAO,QAAQ,oBAAoB,OAAO,QAAQ;CACpD,IAAI,CAAC,kBACH,OAAO;CAGT,MAAM,iBAAiB,iBAAA,GAAA,kBAAA,KAAC,kBAAD,CAAmB,CAAA;CAC1C,OAAA,QAAA,IAAA,aAAgC,eAC5B,iCAAA,+BAA+B,gBAAgB,kBAAkB,IACjE;AACN;AAOA,IAAM,6BACJ,GACA,MACG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;AAEjC,IAAa,QAAQ,MAAM,KAAK,SAAS,UAAU,EACjD,WAGC;CACD,MAAM,SAAS,kBAAA,UAAU;CAEzB,IAAI,+BAAA,YAAY,OAAO,UAErB,OAAO,iBAAA,GAAA,kBAAA,KAAC,WAAD;EAAmB;EAAe,OAD3B,OAAO,OAAO,QAAQ,IAAI,OAAO,EAAG,IACT;CAAQ,CAAA;CAMnD,OAAO,iBAAA,GAAA,kBAAA,KAAC,WAAD;EAAmB;EAAe,QAAA,GAAA,sBAAA,UAHtB,OAAO,OAAO,cAAc,OAExB,IAAa,UAAU,KACL;CAAS,CAAA;AACpD,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