@tanstack/react-router 1.18.2 → 1.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cjs/Matches.cjs +75 -24
  2. package/dist/cjs/Matches.cjs.map +1 -1
  3. package/dist/cjs/Matches.d.cts +2 -3
  4. package/dist/cjs/RouterProvider.cjs +1 -10
  5. package/dist/cjs/RouterProvider.cjs.map +1 -1
  6. package/dist/cjs/awaited.cjs +2 -4
  7. package/dist/cjs/awaited.cjs.map +1 -1
  8. package/dist/cjs/fileRoute.cjs +6 -1
  9. package/dist/cjs/fileRoute.cjs.map +1 -1
  10. package/dist/cjs/fileRoute.d.cts +7 -6
  11. package/dist/cjs/link.cjs.map +1 -1
  12. package/dist/cjs/not-found.cjs.map +1 -1
  13. package/dist/cjs/not-found.d.cts +11 -1
  14. package/dist/cjs/redirects.cjs +1 -1
  15. package/dist/cjs/redirects.cjs.map +1 -1
  16. package/dist/cjs/route.cjs +3 -2
  17. package/dist/cjs/route.cjs.map +1 -1
  18. package/dist/cjs/route.d.cts +25 -24
  19. package/dist/cjs/router.cjs +172 -143
  20. package/dist/cjs/router.cjs.map +1 -1
  21. package/dist/cjs/router.d.cts +12 -8
  22. package/dist/esm/Matches.d.ts +2 -3
  23. package/dist/esm/Matches.js +67 -16
  24. package/dist/esm/Matches.js.map +1 -1
  25. package/dist/esm/RouterProvider.js +1 -10
  26. package/dist/esm/RouterProvider.js.map +1 -1
  27. package/dist/esm/awaited.js +2 -4
  28. package/dist/esm/awaited.js.map +1 -1
  29. package/dist/esm/fileRoute.d.ts +7 -6
  30. package/dist/esm/fileRoute.js +6 -1
  31. package/dist/esm/fileRoute.js.map +1 -1
  32. package/dist/esm/link.js.map +1 -1
  33. package/dist/esm/not-found.d.ts +11 -1
  34. package/dist/esm/not-found.js.map +1 -1
  35. package/dist/esm/redirects.js +1 -1
  36. package/dist/esm/redirects.js.map +1 -1
  37. package/dist/esm/route.d.ts +25 -24
  38. package/dist/esm/route.js +3 -2
  39. package/dist/esm/route.js.map +1 -1
  40. package/dist/esm/router.d.ts +12 -8
  41. package/dist/esm/router.js +163 -134
  42. package/dist/esm/router.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/Matches.tsx +100 -27
  45. package/src/RouterProvider.tsx +1 -12
  46. package/src/awaited.tsx +3 -5
  47. package/src/fileRoute.ts +16 -4
  48. package/src/link.tsx +0 -2
  49. package/src/not-found.tsx +11 -1
  50. package/src/redirects.ts +2 -1
  51. package/src/route.ts +55 -114
  52. package/src/router.ts +267 -175
@@ -5,9 +5,9 @@ import warning from "tiny-warning";
5
5
  import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
6
6
  import { useRouterState } from "./useRouterState.js";
7
7
  import { useRouter } from "./useRouter.js";
8
- import { rootRouteId } from "./route.js";
9
- import { pick } from "./utils.js";
8
+ import { pick, isServer } from "./utils.js";
10
9
  import { isNotFound, DefaultGlobalNotFound, CatchNotFound } from "./not-found.js";
10
+ import { isRedirect } from "./redirects.js";
11
11
  const matchContext = React.createContext(void 0);
12
12
  function Matches() {
13
13
  const router = useRouter();
@@ -81,11 +81,9 @@ function Match({ matchId }) {
81
81
  ResolvedNotFoundBoundary,
82
82
  {
83
83
  fallback: (error) => {
84
- if (!routeNotFoundComponent || error.global && !route.isRoot)
84
+ if (!routeNotFoundComponent || error.routeId && error.routeId !== routeId || !error.routeId && !route.isRoot)
85
85
  throw error;
86
- return React.createElement(routeNotFoundComponent, {
87
- data: error.data
88
- });
86
+ return React.createElement(routeNotFoundComponent, error);
89
87
  },
90
88
  children: /* @__PURE__ */ jsx(MatchInner, { matchId, pendingElement })
91
89
  }
@@ -111,20 +109,34 @@ function MatchInner({
111
109
  "status",
112
110
  "error",
113
111
  "showPending",
114
- "loadPromise",
115
- "notFoundError"
112
+ "loadPromise"
116
113
  ])
117
114
  });
118
- if (match.notFoundError) {
119
- if (routeId === rootRouteId && !route.options.notFoundComponent)
120
- return /* @__PURE__ */ jsx(DefaultGlobalNotFound, {});
121
- invariant(
122
- route.options.notFoundComponent,
123
- "Route matched with notFoundError should have a notFoundComponent"
115
+ const RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent;
116
+ if (match.status === "notFound") {
117
+ invariant(isNotFound(match.error), "Expected a notFound error");
118
+ return renderRouteNotFound(router, route, match.error.data);
119
+ }
120
+ if (match.status === "redirected") {
121
+ invariant(isRedirect(match.error), "Expected a redirect error");
122
+ warning(
123
+ false,
124
+ "Tried to render a redirected route match! This is a weird circumstance, please file an issue!"
124
125
  );
125
- return /* @__PURE__ */ jsx(route.options.notFoundComponent, { data: match.notFoundError });
126
+ return null;
126
127
  }
127
128
  if (match.status === "error") {
129
+ if (isServer) {
130
+ return /* @__PURE__ */ jsx(
131
+ RouteErrorComponent,
132
+ {
133
+ error: match.error,
134
+ info: {
135
+ componentStack: ""
136
+ }
137
+ }
138
+ );
139
+ }
128
140
  if (isServerSideError(match.error)) {
129
141
  const deserializeError = ((_a = router.options.errorSerializer) == null ? void 0 : _a.deserialize) ?? defaultDeserializeError;
130
142
  throw deserializeError(match.error.data);
@@ -151,7 +163,28 @@ function MatchInner({
151
163
  );
152
164
  }
153
165
  const Outlet = React.memo(function Outlet2() {
166
+ const router = useRouter();
154
167
  const matchId = React.useContext(matchContext);
168
+ const routeId = useRouterState({
169
+ select: (s) => {
170
+ var _a;
171
+ return (_a = getRenderedMatches(s).find((d) => d.id === matchId)) == null ? void 0 : _a.routeId;
172
+ }
173
+ });
174
+ const route = router.routesById[routeId];
175
+ const { parentGlobalNotFound } = useRouterState({
176
+ select: (s) => {
177
+ const matches = getRenderedMatches(s);
178
+ const parentMatch = matches.find((d) => d.id === matchId);
179
+ invariant(
180
+ parentMatch,
181
+ `Could not find parent match for matchId "${matchId}"`
182
+ );
183
+ return {
184
+ parentGlobalNotFound: parentMatch.globalNotFound
185
+ };
186
+ }
187
+ });
155
188
  const childMatchId = useRouterState({
156
189
  select: (s) => {
157
190
  var _a;
@@ -160,11 +193,29 @@ const Outlet = React.memo(function Outlet2() {
160
193
  return (_a = matches[index + 1]) == null ? void 0 : _a.id;
161
194
  }
162
195
  });
196
+ if (parentGlobalNotFound) {
197
+ return renderRouteNotFound(router, route, void 0);
198
+ }
163
199
  if (!childMatchId) {
164
200
  return null;
165
201
  }
166
202
  return /* @__PURE__ */ jsx(Match, { matchId: childMatchId });
167
203
  });
204
+ function renderRouteNotFound(router, route, data) {
205
+ if (!route.options.notFoundComponent) {
206
+ if (router.options.defaultNotFoundComponent) {
207
+ return /* @__PURE__ */ jsx(router.options.defaultNotFoundComponent, { data });
208
+ }
209
+ if (process.env.NODE_ENV === "development") {
210
+ warning(
211
+ route.options.notFoundComponent,
212
+ `A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<div>Not Found<div>)`
213
+ );
214
+ }
215
+ return /* @__PURE__ */ jsx(DefaultGlobalNotFound, {});
216
+ }
217
+ return /* @__PURE__ */ jsx(route.options.notFoundComponent, { data });
218
+ }
168
219
  function useMatchRoute() {
169
220
  useRouterState({ select: (s) => [s.location, s.resolvedLocation] });
170
221
  const { matchRoute } = useRouter();
@@ -214,7 +265,7 @@ function useMatch(opts) {
214
265
  const matchSelection = useRouterState({
215
266
  select: (state) => {
216
267
  const match = getRenderedMatches(state).find(
217
- (d) => d.id === nearestMatchId
268
+ (d) => (opts == null ? void 0 : opts.from) ? (opts == null ? void 0 : opts.from) === d.routeId : d.id === nearestMatchId
218
269
  );
219
270
  invariant(
220
271
  match,
@@ -1 +1 @@
1
- {"version":3,"file":"Matches.js","sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { ResolveRelativePath, ToOptions } from './link'\nimport {\n AnyRoute,\n ReactNode,\n RootSearchSchema,\n StaticDataRouteOption,\n UpdatableStaticRouteOption,\n rootRouteId,\n} from './route'\nimport {\n AllParams,\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { RegisteredRouter, RouterState } from './router'\nimport { DeepPartial, Expand, NoInfer, StrictOrFrom, pick } from './utils'\nimport {\n CatchNotFound,\n DefaultGlobalNotFound,\n NotFoundError,\n isNotFound,\n} from './not-found'\n\nexport const matchContext = React.createContext<string | undefined>(undefined)\n\nexport interface RouteMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n> {\n id: string\n routeId: TRouteId\n pathname: string\n params: TReturnIntersection extends false\n ? RouteById<TRouteTree, TRouteId>['types']['allParams']\n : Expand<Partial<AllParams<TRouteTree>>>\n status: 'pending' | 'success' | 'error'\n isFetching: boolean\n showPending: boolean\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n loadPromise?: Promise<void>\n loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']\n routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext']\n context: RouteById<TRouteTree, TRouteId>['types']['allContext']\n search: TReturnIntersection extends false\n ? Exclude<\n RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],\n RootSearchSchema\n >\n : Expand<\n Partial<Omit<FullSearchSchema<TRouteTree>, keyof RootSearchSchema>>\n >\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps']\n preload: boolean\n invalid: boolean\n pendingPromise?: Promise<void>\n meta?: JSX.IntrinsicElements['meta'][]\n links?: JSX.IntrinsicElements['link'][]\n scripts?: JSX.IntrinsicElements['script'][]\n headers?: Record<string, string>\n notFoundError?: NotFoundError\n staticData: StaticDataRouteOption\n}\n\nexport type AnyRouteMatch = RouteMatch<any, any>\n\nexport function Matches() {\n const router = useRouter()\n const matchId = useRouterState({\n select: (s) => {\n return getRenderedMatches(s)[0]?.id\n },\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <CatchBoundary\n getResetKey={() => router.state.resolvedLocation.state?.key!}\n errorComponent={ErrorComponent}\n onCatch={(error) => {\n warning(\n false,\n `The following error wasn't caught by any route! 👇 At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n console.error(error)\n }}\n >\n {matchId ? <Match matchId={matchId} /> : null}\n </CatchBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction SafeFragment(props: any) {\n return <>{props.children}</>\n}\n\nexport function Match({ matchId }: { matchId: string }) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route = router.routesById[routeId]!\n\n const PendingComponent = (route.options.pendingComponent ??\n router.options.defaultPendingComponent) as any\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ??\n router.options.defaultErrorComponent ??\n ErrorComponent\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound 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 ResolvedSuspenseBoundary =\n route.options.wrapInSuspense ??\n PendingComponent ??\n route.options.component?.preload ??\n route.options.pendingComponent?.preload ??\n (route.options.errorComponent as any)?.preload\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 return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => router.state.resolvedLocation.state?.key!}\n errorComponent={routeErrorComponent}\n onCatch={(error) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n warning(false, `Error in route match: ${matchId}`)\n console.error(error)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or doesn't handle global not founds, forward it up the tree\n if (!routeNotFoundComponent || (error.global && !route.isRoot))\n throw error\n\n return React.createElement(routeNotFoundComponent, {\n data: error.data,\n })\n }}\n >\n <MatchInner matchId={matchId!} pendingElement={pendingElement} />\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction MatchInner({\n matchId,\n pendingElement,\n}: {\n matchId: string\n pendingElement: any\n}): any {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const match = useRouterState({\n select: (s) =>\n pick(getRenderedMatches(s).find((d) => d.id === matchId)!, [\n 'status',\n 'error',\n 'showPending',\n 'loadPromise',\n 'notFoundError',\n ]),\n })\n\n // If a global not-found is found, and it's the root route, render the global not-found component.\n if (match.notFoundError) {\n if (routeId === rootRouteId && !route.options.notFoundComponent)\n return <DefaultGlobalNotFound />\n\n invariant(\n route.options.notFoundComponent,\n 'Route matched with notFoundError should have a notFoundComponent',\n )\n\n return <route.options.notFoundComponent data={match.notFoundError} />\n }\n\n if (match.status === 'error') {\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n throw deserializeError(match.error.data)\n } else {\n throw match.error\n }\n }\n\n if (match.status === 'pending') {\n if (match.showPending) {\n return pendingElement\n }\n throw match.loadPromise\n }\n\n if (match.status === 'success') {\n let Comp = route.options.component ?? router.options.defaultComponent\n\n if (Comp) {\n return <Comp />\n }\n\n return <Outlet />\n }\n\n invariant(\n false,\n 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!',\n )\n}\n\nexport const Outlet = React.memo(function Outlet() {\n const matchId = React.useContext(matchContext)\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = getRenderedMatches(s)\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (!childMatchId) {\n return null\n }\n\n return <Match matchId={childMatchId} />\n})\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n\nexport type UseMatchRouteOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n Options extends ToOptions<\n TRouteTree,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n RelaxedOptions = Omit<Options, 'search' | 'params'> &\n DeepPartial<Pick<Options, 'search' | 'params'>>,\n> = RelaxedOptions & MatchRouteOptions\n\nexport function useMatchRoute<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>() {\n useRouterState({ select: (s) => [s.location, s.resolvedLocation] })\n const { matchRoute } = useRouter()\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n >(\n opts: UseMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n ): false | RouteById<TRouteTree, TResolved>['types']['allParams'] => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: RouteByPath<\n TRouteTree,\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => ReactNode)\n | React.ReactNode\n}\n\nexport function MatchRoute<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n>(\n props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any)\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return !!params ? props.children : null\n}\n\nexport function getRenderedMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(state: RouterState<TRouteTree>) {\n return state.pendingMatches?.some((d) => d.showPending)\n ? state.pendingMatches\n : state.matches\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TReturnIntersection extends boolean = false,\n TRouteMatchState = RouteMatch<TRouteTree, TFrom, TReturnIntersection>,\n TSelected = TRouteMatchState,\n>(\n opts: StrictOrFrom<TFrom, TReturnIntersection> & {\n select?: (match: TRouteMatchState) => TSelected\n },\n): TSelected {\n const router = useRouter()\n const nearestMatchId = React.useContext(matchContext)\n\n const nearestMatchRouteId = getRenderedMatches(router.state).find(\n (d) => d.id === nearestMatchId,\n )?.routeId\n\n const matchRouteId = (() => {\n const matches = getRenderedMatches(router.state)\n const match = opts?.from\n ? matches.find((d) => d.routeId === opts?.from)\n : matches.find((d) => d.id === nearestMatchId)\n return match!.routeId\n })()\n\n if (opts?.strict ?? true) {\n invariant(\n nearestMatchRouteId == matchRouteId,\n `useMatch(\"${\n matchRouteId as string\n }\") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch(\"${\n matchRouteId as string\n }\", { strict: false })' or 'useRoute(\"${\n matchRouteId as string\n }\")' instead?`,\n )\n }\n\n const matchSelection = useRouterState({\n select: (state) => {\n const match = getRenderedMatches(state).find(\n (d) => d.id === nearestMatchId,\n )\n\n invariant(\n match,\n `Could not find ${\n opts?.from\n ? `an active match from \"${opts.from}\"`\n : 'a nearest match!'\n }`,\n )\n\n return opts?.select ? opts.select(match as any) : match\n },\n })\n\n return matchSelection as any\n}\n\nexport function useMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = TRouteMatch[],\n>(opts?: {\n select?: (matches: TRouteMatch[]) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n return useRouterState({\n select: (state) => {\n const matches = getRenderedMatches(state)\n return opts?.select\n ? opts.select(matches as TRouteMatch[])\n : (matches as T)\n },\n })\n}\n\nexport function useParentMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = TRouteMatch[],\n>(opts?: {\n select?: (matches: TRouteMatch[]) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select\n ? opts.select(matches as TRouteMatch[])\n : (matches as T)\n },\n })\n}\n\nexport function useChildMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = TRouteMatch[],\n>(opts?: {\n select?: (matches: TRouteMatch[]) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select\n ? opts.select(matches as TRouteMatch[])\n : (matches as T)\n },\n })\n}\n\nexport function useLoaderDeps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderDeps'],\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TSelected {\n return useMatch({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s?.loaderDeps)\n : s?.loaderDeps\n },\n })\n}\n\nexport function useLoaderData<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderData'],\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TSelected {\n return useMatch({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s?.loaderData)\n : s?.loaderData\n },\n })\n}\n\nexport function isServerSideError(error: unknown): error is {\n __isServerError: true\n data: Record<string, any>\n} {\n if (!(typeof error === 'object' && error && 'data' in error)) return false\n if (!('__isServerError' in error && error.__isServerError)) return false\n if (!(typeof error.data === 'object' && error.data)) return false\n\n return error.__isServerError === true\n}\n\nexport function defaultDeserializeError(serializedData: Record<string, any>) {\n if ('name' in serializedData && 'message' in serializedData) {\n const error = new Error(serializedData.message)\n error.name = serializedData.name\n return error\n }\n\n return serializedData.data\n}\n"],"names":["_a","Outlet"],"mappings":";;;;;;;;;;AAiCa,MAAA,eAAe,MAAM,cAAkC,MAAS;AAiDtE,SAAS,UAAU;AACxB,QAAM,SAAS;AACf,QAAM,UAAU,eAAe;AAAA,IAC7B,QAAQ,CAAC,MAAM;;AACb,cAAO,wBAAmB,CAAC,EAAE,CAAC,MAAvB,mBAA0B;AAAA,IACnC;AAAA,EAAA,CACD;AAED,SACG,oBAAA,aAAa,UAAb,EAAsB,OAAO,SAC5B,UAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAa,MAAA;;AAAM,4BAAO,MAAM,iBAAiB,UAA9B,mBAAqC;AAAA;AAAA,MACxD,gBAAgB;AAAA,MAChB,SAAS,CAAC,UAAU;AAClB;AAAA,UACE;AAAA,UACA;AAAA,QAAA;AAEF,gBAAQ,MAAM,KAAK;AAAA,MACrB;AAAA,MAEC,UAAU,UAAA,oBAAC,OAAM,EAAA,QAAkB,CAAA,IAAK;AAAA,IAAA;AAAA,EAE7C,EAAA,CAAA;AAEJ;AAEA,SAAS,aAAa,OAAY;AACzB,SAAA,oBAAA,UAAA,EAAG,gBAAM,SAAS,CAAA;AAC3B;AAEgB,SAAA,MAAM,EAAE,WAAgC;;AACtD,QAAM,SAAS;AACf,QAAM,UAAU,eAAe;AAAA,IAC7B,QAAQ,CAAC;;AACP,cAAAA,MAAA,mBAAmB,CAAC,EAAE,KAAK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AU,kBAAkB,aAAa,gBAAgB;AAC3D,UAAM,QAAQ,IAAI,MAAM,eAAe,OAAO;AAC9C,UAAM,OAAO,eAAe;AACrB,WAAA;AAAA,EACT;AAEA,SAAO,eAAe;AACxB;"}
1
+ {"version":3,"file":"Matches.js","sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { ResolveRelativePath, ToOptions } from './link'\nimport {\n AnyRoute,\n ReactNode,\n RootSearchSchema,\n StaticDataRouteOption,\n} from './route'\nimport {\n AllParams,\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport { AnyRouter, RegisteredRouter, RouterState } from './router'\nimport {\n DeepPartial,\n Expand,\n NoInfer,\n StrictOrFrom,\n isServer,\n pick,\n} from './utils'\nimport { CatchNotFound, DefaultGlobalNotFound, isNotFound } from './not-found'\nimport { isRedirect } from './redirects'\n\nexport const matchContext = React.createContext<string | undefined>(undefined)\n\nexport interface RouteMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n> {\n id: string\n routeId: TRouteId\n pathname: string\n params: TReturnIntersection extends false\n ? RouteById<TRouteTree, TRouteId>['types']['allParams']\n : Expand<Partial<AllParams<TRouteTree>>>\n status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'\n isFetching: boolean\n showPending: boolean\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n loadPromise?: Promise<void>\n loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']\n routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext']\n context: RouteById<TRouteTree, TRouteId>['types']['allContext']\n search: TReturnIntersection extends false\n ? Exclude<\n RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],\n RootSearchSchema\n >\n : Expand<\n Partial<Omit<FullSearchSchema<TRouteTree>, keyof RootSearchSchema>>\n >\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps']\n preload: boolean\n invalid: boolean\n pendingPromise?: Promise<void>\n meta?: JSX.IntrinsicElements['meta'][]\n links?: JSX.IntrinsicElements['link'][]\n scripts?: JSX.IntrinsicElements['script'][]\n headers?: Record<string, string>\n globalNotFound?: boolean\n staticData: StaticDataRouteOption\n}\n\nexport type AnyRouteMatch = RouteMatch<any, any>\n\nexport function Matches() {\n const router = useRouter()\n const matchId = useRouterState({\n select: (s) => {\n return getRenderedMatches(s)[0]?.id\n },\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <CatchBoundary\n getResetKey={() => router.state.resolvedLocation.state?.key!}\n errorComponent={ErrorComponent}\n onCatch={(error) => {\n warning(\n false,\n `The following error wasn't caught by any route! 👇 At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n console.error(error)\n }}\n >\n {matchId ? <Match matchId={matchId} /> : null}\n </CatchBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction SafeFragment(props: any) {\n return <>{props.children}</>\n}\n\nexport function Match({ matchId }: { matchId: string }) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route = router.routesById[routeId]!\n\n const PendingComponent = (route.options.pendingComponent ??\n router.options.defaultPendingComponent) as any\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ??\n router.options.defaultErrorComponent ??\n ErrorComponent\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound 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 ResolvedSuspenseBoundary =\n route.options.wrapInSuspense ??\n PendingComponent ??\n route.options.component?.preload ??\n route.options.pendingComponent?.preload ??\n (route.options.errorComponent as any)?.preload\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 return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => router.state.resolvedLocation.state?.key!}\n errorComponent={routeErrorComponent}\n onCatch={(error) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n warning(false, `Error in route match: ${matchId}`)\n console.error(error)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n <MatchInner matchId={matchId!} pendingElement={pendingElement} />\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction MatchInner({\n matchId,\n pendingElement,\n}: {\n matchId: string\n pendingElement: any\n}): any {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const match = useRouterState({\n select: (s) =>\n pick(getRenderedMatches(s).find((d) => d.id === matchId)!, [\n 'status',\n 'error',\n 'showPending',\n 'loadPromise',\n ]),\n })\n\n const RouteErrorComponent =\n (route.options.errorComponent ?? router.options.defaultErrorComponent) ||\n ErrorComponent\n\n if (match.status === 'notFound') {\n invariant(isNotFound(match.error), 'Expected a notFound error')\n\n return renderRouteNotFound(router, route, match.error.data)\n }\n\n if (match.status === 'redirected') {\n // Redirects should be handled by the router transition. If we happen to\n // encounter a redirect here, it's a bug. Let's warn, but render nothing.\n invariant(isRedirect(match.error), 'Expected a redirect error')\n\n warning(\n false,\n 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',\n )\n\n return null\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (isServer) {\n return (\n <RouteErrorComponent\n error={match.error}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n throw deserializeError(match.error.data)\n } else {\n throw match.error\n }\n }\n\n if (match.status === 'pending') {\n if (match.showPending) {\n return pendingElement\n }\n throw match.loadPromise\n }\n\n if (match.status === 'success') {\n let Comp = route.options.component ?? router.options.defaultComponent\n\n if (Comp) {\n return <Comp />\n }\n\n return <Outlet />\n }\n\n invariant(\n false,\n 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!',\n )\n}\n\nexport const Outlet = React.memo(function Outlet() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n const routeId = useRouterState({\n select: (s) =>\n getRenderedMatches(s).find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const { parentGlobalNotFound } = useRouterState({\n select: (s) => {\n const matches = getRenderedMatches(s)\n const parentMatch = matches.find((d) => d.id === matchId)\n invariant(\n parentMatch,\n `Could not find parent match for matchId \"${matchId}\"`,\n )\n return {\n parentGlobalNotFound: parentMatch.globalNotFound,\n }\n },\n })\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = getRenderedMatches(s)\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (parentGlobalNotFound) {\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n return <Match matchId={childMatchId} />\n})\n\nfunction renderRouteNotFound(router: AnyRouter, route: AnyRoute, data: any) {\n if (!route.options.notFoundComponent) {\n if (router.options.defaultNotFoundComponent) {\n return <router.options.defaultNotFoundComponent data={data} />\n }\n\n if (process.env.NODE_ENV === 'development') {\n warning(\n route.options.notFoundComponent,\n `A notFoundError was encountered on the route with ID \"${route.id}\", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<div>Not Found<div>)`,\n )\n }\n\n return <DefaultGlobalNotFound />\n }\n\n return <route.options.notFoundComponent data={data} />\n}\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n\nexport type UseMatchRouteOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n Options extends ToOptions<\n TRouteTree,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n RelaxedOptions = Omit<Options, 'search' | 'params'> &\n DeepPartial<Pick<Options, 'search' | 'params'>>,\n> = RelaxedOptions & MatchRouteOptions\n\nexport function useMatchRoute<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>() {\n useRouterState({ select: (s) => [s.location, s.resolvedLocation] })\n const { matchRoute } = useRouter()\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n >(\n opts: UseMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n ): false | RouteById<TRouteTree, TResolved>['types']['allParams'] => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: RouteByPath<\n TRouteTree,\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => ReactNode)\n | React.ReactNode\n}\n\nexport function MatchRoute<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n>(\n props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any)\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return !!params ? props.children : null\n}\n\nexport function getRenderedMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(state: RouterState<TRouteTree>) {\n return state.pendingMatches?.some((d) => d.showPending)\n ? state.pendingMatches\n : state.matches\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TReturnIntersection extends boolean = false,\n TRouteMatchState = RouteMatch<TRouteTree, TFrom, TReturnIntersection>,\n TSelected = TRouteMatchState,\n>(\n opts: StrictOrFrom<TFrom, TReturnIntersection> & {\n select?: (match: TRouteMatchState) => TSelected\n },\n): TSelected {\n const router = useRouter()\n const nearestMatchId = React.useContext(matchContext)\n\n const nearestMatchRouteId = getRenderedMatches(router.state).find(\n (d) => d.id === nearestMatchId,\n )?.routeId\n\n const matchRouteId = (() => {\n const matches = getRenderedMatches(router.state)\n const match = opts?.from\n ? matches.find((d) => d.routeId === opts?.from)\n : matches.find((d) => d.id === nearestMatchId)\n return match!.routeId\n })()\n\n if (opts?.strict ?? true) {\n invariant(\n nearestMatchRouteId == matchRouteId,\n `useMatch(\"${\n matchRouteId as string\n }\") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch(\"${\n matchRouteId as string\n }\", { strict: false })' or 'useRoute(\"${\n matchRouteId as string\n }\")' instead?`,\n )\n }\n\n const matchSelection = useRouterState({\n select: (state) => {\n const match = getRenderedMatches(state).find((d) =>\n opts?.from ? opts?.from === d.routeId : d.id === nearestMatchId,\n )\n\n invariant(\n match,\n `Could not find ${\n opts?.from\n ? `an active match from \"${opts.from}\"`\n : 'a nearest match!'\n }`,\n )\n\n return opts?.select ? opts.select(match as any) : match\n },\n })\n\n return matchSelection as any\n}\n\nexport function useMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = TRouteMatch[],\n>(opts?: {\n select?: (matches: TRouteMatch[]) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n return useRouterState({\n select: (state) => {\n const matches = getRenderedMatches(state)\n return opts?.select\n ? opts.select(matches as TRouteMatch[])\n : (matches as T)\n },\n })\n}\n\nexport function useParentMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = TRouteMatch[],\n>(opts?: {\n select?: (matches: TRouteMatch[]) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select\n ? opts.select(matches as TRouteMatch[])\n : (matches as T)\n },\n })\n}\n\nexport function useChildMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = RouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = TRouteMatch[],\n>(opts?: {\n select?: (matches: TRouteMatch[]) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select\n ? opts.select(matches as TRouteMatch[])\n : (matches as T)\n },\n })\n}\n\nexport function useLoaderDeps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderDeps'],\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TSelected {\n return useMatch({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s?.loaderDeps)\n : s?.loaderDeps\n },\n })\n}\n\nexport function useLoaderData<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<\n TRouteTree,\n TFrom\n >,\n TSelected = Required<TRouteMatch>['loaderData'],\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (match: TRouteMatch) => TSelected\n },\n): TSelected {\n return useMatch({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s?.loaderData)\n : s?.loaderData\n },\n })\n}\n\nexport function isServerSideError(error: unknown): error is {\n __isServerError: true\n data: Record<string, any>\n} {\n if (!(typeof error === 'object' && error && 'data' in error)) return false\n if (!('__isServerError' in error && error.__isServerError)) return false\n if (!(typeof error.data === 'object' && error.data)) return false\n\n return error.__isServerError === true\n}\n\nexport function defaultDeserializeError(serializedData: Record<string, any>) {\n if ('name' in serializedData && 'message' in serializedData) {\n const error = new Error(serializedData.message)\n error.name = serializedData.name\n return error\n }\n\n return serializedData.data\n}\n"],"names":["_a","Outlet"],"mappings":";;;;;;;;;;AAkCa,MAAA,eAAe,MAAM,cAAkC,MAAS;AAiDtE,SAAS,UAAU;AACxB,QAAM,SAAS;AACf,QAAM,UAAU,eAAe;AAAA,IAC7B,QAAQ,CAAC,MAAM;;AACb,cAAO,wBAAmB,CAAC,EAAE,CAAC,MAAvB,mBAA0B;AAAA,IACnC;AAAA,EAAA,CACD;AAED,SACG,oBAAA,aAAa,UAAb,EAAsB,OAAO,SAC5B,UAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAa,MAAA;;AAAM,4BAAO,MAAM,iBAAiB,UAA9B,mBAAqC;AAAA;AAAA,MACxD,gBAAgB;AAAA,MAChB,SAAS,CAAC,UAAU;AAClB;AAAA,UACE;AAAA,UACA;AAAA,QAAA;AAEF,gBAAQ,MAAM,KAAK;AAAA,MACrB;AAAA,MAEC,UAAU,UAAA,oBAAC,OAAM,EAAA,QAAkB,CAAA,IAAK;AAAA,IAAA;AAAA,EAE7C,EAAA,CAAA;AAEJ;AAEA,SAAS,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;AACH;AAEO,SAAS,kBAAkB,OAGhC;AACA,MAAI,EAAE,OAAO,UAAU,YAAY,SAAS,UAAU;AAAe,WAAA;AACjE,MAAA,EAAE,qBAAqB,SAAS,MAAM;AAAyB,WAAA;AACnE,MAAI,EAAE,OAAO,MAAM,SAAS,YAAY,MAAM;AAAc,WAAA;AAE5D,SAAO,MAAM,oBAAoB;AACnC;AAEO,SAAS,wBAAwB,gBAAqC;AACvE,MAAA,UAAU,kBAAkB,aAAa,gBAAgB;AAC3D,UAAM,QAAQ,IAAI,MAAM,eAAe,OAAO;AAC9C,UAAM,OAAO,eAAe;AACrB,WAAA;AAAA,EACT;AAEA,SAAO,eAAe;AACxB;"}
@@ -66,19 +66,10 @@ function Transitioner() {
66
66
  useLayoutEffect(() => {
67
67
  const unsub = router.history.subscribe(() => {
68
68
  router.latestLocation = router.parseLocation(router.latestLocation);
69
- if (routerState.location !== router.latestLocation) {
69
+ if (router.state.location !== router.latestLocation) {
70
70
  tryLoad();
71
71
  }
72
72
  });
73
- const nextLocation = router.buildLocation({
74
- search: true,
75
- params: true,
76
- hash: true,
77
- state: true
78
- });
79
- if (routerState.location.href !== nextLocation.href) {
80
- router.commitLocation({ ...nextLocation, replace: true });
81
- }
82
73
  return () => {
83
74
  unsub();
84
75
  };
@@ -1 +1 @@
1
- {"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Matches } from './Matches'\nimport { NavigateOptions, ToOptions } from './link'\nimport { ParsedLocation } from './location'\nimport { AnyRoute } from './route'\nimport { RoutePaths } from './routeInfo'\nimport { RegisteredRouter, Router, RouterOptions, RouterState } from './router'\nimport { pick, useLayoutEffect } from './utils'\n\nimport { RouteMatch } from './Matches'\nimport { useRouter } from './useRouter'\nimport { useRouterState } from './useRouterState'\nimport { getRouterContext } from './routerContext'\n\nconst useTransition =\n React.useTransition ||\n (() => [\n false,\n (cb) => {\n cb()\n },\n ])\n\nexport interface CommitLocationOptions {\n replace?: boolean\n resetScroll?: boolean\n startTransition?: boolean\n}\n\nexport interface MatchLocation {\n to?: string | number | null\n fuzzy?: boolean\n caseSensitive?: boolean\n from?: string\n}\n\nexport type NavigateFn = <\n TTo extends string,\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(\n opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Promise<void>\n\nexport type BuildLocationFn<TRouteTree extends AnyRoute> = <\n TTo extends string,\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(\n opts: ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n leaveParams?: boolean\n },\n) => ParsedLocation\n\nexport type InjectedHtmlEntry = string | (() => Promise<string> | string)\n\nexport function RouterProvider<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest?.context,\n },\n } as any)\n\n const matches = router.options.InnerWrap ? (\n <router.options.InnerWrap>\n <Matches />\n </router.options.InnerWrap>\n ) : (\n <Matches />\n )\n\n const routerContext = getRouterContext()\n\n const provider = (\n <routerContext.Provider value={router}>\n {matches}\n <Transitioner />\n </routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\nfunction Transitioner() {\n const router = useRouter()\n const mountLoadForRouter = React.useRef({ router, mounted: false })\n const routerState = useRouterState({\n select: (s) =>\n pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning']),\n })\n\n const [isTransitioning, startReactTransition] = useTransition()\n\n router.startReactTransition = startReactTransition\n\n React.useEffect(() => {\n if (isTransitioning) {\n router.__store.setState((s) => ({\n ...s,\n isTransitioning,\n }))\n }\n }, [isTransitioning])\n\n const tryLoad = () => {\n const apply = (cb: () => void) => {\n if (!routerState.isTransitioning) {\n startReactTransition(() => cb())\n } else {\n cb()\n }\n }\n\n apply(() => {\n try {\n router.load()\n } catch (err) {\n console.error(err)\n }\n })\n }\n\n useLayoutEffect(() => {\n const unsub = router.history.subscribe(() => {\n router.latestLocation = router.parseLocation(router.latestLocation)\n if (routerState.location !== router.latestLocation) {\n tryLoad()\n }\n })\n\n const nextLocation = router.buildLocation({\n search: true,\n params: true,\n hash: true,\n state: true,\n })\n\n if (routerState.location.href !== nextLocation.href) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n\n return () => {\n unsub()\n }\n }, [router.history])\n\n useLayoutEffect(() => {\n if (\n (React.useTransition as any)\n ? routerState.isTransitioning && !isTransitioning\n : true &&\n !routerState.isLoading &&\n routerState.resolvedLocation !== routerState.location\n ) {\n router.emit({\n type: 'onResolved',\n fromLocation: routerState.resolvedLocation,\n toLocation: routerState.location,\n pathChanged:\n routerState.location!.href !== routerState.resolvedLocation?.href,\n })\n\n if ((document as any).querySelector) {\n if (routerState.location.hash !== '') {\n const el = document.getElementById(\n routerState.location.hash,\n ) as HTMLElement | null\n if (el) {\n el.scrollIntoView()\n }\n }\n }\n\n router.__store.setState((s) => ({\n ...s,\n isTransitioning: false,\n resolvedLocation: s.location,\n }))\n }\n }, [\n routerState.isTransitioning,\n isTransitioning,\n routerState.isLoading,\n routerState.resolvedLocation,\n routerState.location,\n ])\n\n useLayoutEffect(() => {\n if (\n window.__TSR_DEHYDRATED__ ||\n (mountLoadForRouter.current.router === router &&\n mountLoadForRouter.current.mounted)\n ) {\n return\n }\n mountLoadForRouter.current = { router, mounted: true }\n tryLoad()\n }, [router])\n\n return null\n}\n\nexport function getRouteMatch<TRouteTree extends AnyRoute>(\n state: RouterState<TRouteTree>,\n id: string,\n): undefined | RouteMatch<TRouteTree> {\n return [\n ...state.cachedMatches,\n ...(state.pendingMatches ?? []),\n ...state.matches,\n ].find((d) => d.id === id)\n}\n\nexport type RouterProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {\n router: Router<TRouteTree>\n context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>\n}\n"],"names":[],"mappings":";;;;;;;AAcA,MAAM,gBACJ,MAAM,kBACL,MAAM;AAAA,EACL;AAAA,EACA,CAAC,OAAO;AACH;EACL;AACF;AAsCK,SAAS,eAGd,EAAE,QAAQ,GAAG,QAA8C;AAE3D,SAAO,OAAO;AAAA,IACZ,GAAG,OAAO;AAAA,IACV,GAAG;AAAA,IACH,SAAS;AAAA,MACP,GAAG,OAAO,QAAQ;AAAA,MAClB,GAAG,6BAAM;AAAA,IACX;AAAA,EAAA,CACM;AAER,QAAM,UAAU,OAAO,QAAQ,gCAC5B,OAAO,QAAQ,WAAf,EACC,UAAC,oBAAA,SAAA,EAAQ,EACX,CAAA,wBAEC,SAAQ,CAAA,CAAA;AAGX,QAAM,gBAAgB;AAEtB,QAAM,WACH,qBAAA,cAAc,UAAd,EAAuB,OAAO,QAC5B,UAAA;AAAA,IAAA;AAAA,wBACA,cAAa,EAAA;AAAA,EAChB,EAAA,CAAA;AAGE,MAAA,OAAO,QAAQ,MAAM;AACvB,WAAQ,oBAAA,OAAO,QAAQ,MAAf,EAAqB,UAAS,SAAA,CAAA;AAAA,EACxC;AAEO,SAAA;AACT;AAEA,SAAS,eAAe;AACtB,QAAM,SAAS;AACf,QAAM,qBAAqB,MAAM,OAAO,EAAE,QAAQ,SAAS,OAAO;AAClE,QAAM,cAAc,eAAe;AAAA,IACjC,QAAQ,CAAC,MACP,KAAK,GAAG,CAAC,aAAa,YAAY,oBAAoB,iBAAiB,CAAC;AAAA,EAAA,CAC3E;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iBAAY,qBAAZ,mBAA8B;AAAA,MAAA,CAChE;AAED,UAAK,SAAiB,eAAe;AAC/B,YAAA,YAAY,SAAS,SAAS,IAAI;AACpC,gBAAM,KAAK,SAAS;AAAA,YAClB,YAAY,SAAS;AAAA,UAAA;AAEvB,cAAI,IAAI;AACN,eAAG,eAAe;AAAA,UACpB;AAAA,QACF;AAAA,MACF;AAEO,aAAA,QAAQ,SAAS,CAAC,OAAO;AAAA,QAC9B,GAAG;AAAA,QACH,iBAAiB;AAAA,QACjB,kBAAkB,EAAE;AAAA,MACpB,EAAA;AAAA,IACJ;AAAA,EAAA,GACC;AAAA,IACD,YAAY;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,YAAY;AAAA,EAAA,CACb;AAED,kBAAgB,MAAM;AAElB,QAAA,OAAO,sBACN,mBAAmB,QAAQ,WAAW,UACrC,mBAAmB,QAAQ,SAC7B;AACA;AAAA,IACF;AACA,uBAAmB,UAAU,EAAE,QAAQ,SAAS,KAAK;AAC7C;EAAA,GACP,CAAC,MAAM,CAAC;AAEJ,SAAA;AACT;AAEgB,SAAA,cACd,OACA,IACoC;AAC7B,SAAA;AAAA,IACL,GAAG,MAAM;AAAA,IACT,GAAI,MAAM,kBAAkB,CAAC;AAAA,IAC7B,GAAG,MAAM;AAAA,EAAA,EACT,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE;AAC3B;"}
1
+ {"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Matches } from './Matches'\nimport { NavigateOptions, ToOptions } from './link'\nimport { ParsedLocation } from './location'\nimport { AnyRoute } from './route'\nimport { RoutePaths } from './routeInfo'\nimport { RegisteredRouter, Router, RouterOptions, RouterState } from './router'\nimport { pick, useLayoutEffect } from './utils'\n\nimport { RouteMatch } from './Matches'\nimport { useRouter } from './useRouter'\nimport { useRouterState } from './useRouterState'\nimport { getRouterContext } from './routerContext'\n\nconst useTransition =\n React.useTransition ||\n (() => [\n false,\n (cb) => {\n cb()\n },\n ])\n\nexport interface CommitLocationOptions {\n replace?: boolean\n resetScroll?: boolean\n startTransition?: boolean\n}\n\nexport interface MatchLocation {\n to?: string | number | null\n fuzzy?: boolean\n caseSensitive?: boolean\n from?: string\n}\n\nexport type NavigateFn = <\n TTo extends string,\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(\n opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Promise<void>\n\nexport type BuildLocationFn<TRouteTree extends AnyRoute> = <\n TTo extends string,\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(\n opts: ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n leaveParams?: boolean\n },\n) => ParsedLocation\n\nexport type InjectedHtmlEntry = string | (() => Promise<string> | string)\n\nexport function RouterProvider<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest?.context,\n },\n } as any)\n\n const matches = router.options.InnerWrap ? (\n <router.options.InnerWrap>\n <Matches />\n </router.options.InnerWrap>\n ) : (\n <Matches />\n )\n\n const routerContext = getRouterContext()\n\n const provider = (\n <routerContext.Provider value={router}>\n {matches}\n <Transitioner />\n </routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\nfunction Transitioner() {\n const router = useRouter()\n const mountLoadForRouter = React.useRef({ router, mounted: false })\n const routerState = useRouterState({\n select: (s) =>\n pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning']),\n })\n\n const [isTransitioning, startReactTransition] = useTransition()\n\n router.startReactTransition = startReactTransition\n\n React.useEffect(() => {\n if (isTransitioning) {\n router.__store.setState((s) => ({\n ...s,\n isTransitioning,\n }))\n }\n }, [isTransitioning])\n\n const tryLoad = () => {\n const apply = (cb: () => void) => {\n if (!routerState.isTransitioning) {\n startReactTransition(() => cb())\n } else {\n cb()\n }\n }\n\n apply(() => {\n try {\n router.load()\n } catch (err) {\n console.error(err)\n }\n })\n }\n\n useLayoutEffect(() => {\n const unsub = router.history.subscribe(() => {\n router.latestLocation = router.parseLocation(router.latestLocation)\n if (router.state.location !== router.latestLocation) {\n tryLoad()\n }\n })\n\n return () => {\n unsub()\n }\n }, [router.history])\n\n useLayoutEffect(() => {\n if (\n (React.useTransition as any)\n ? routerState.isTransitioning && !isTransitioning\n : true &&\n !routerState.isLoading &&\n routerState.resolvedLocation !== routerState.location\n ) {\n router.emit({\n type: 'onResolved',\n fromLocation: routerState.resolvedLocation,\n toLocation: routerState.location,\n pathChanged:\n routerState.location!.href !== routerState.resolvedLocation?.href,\n })\n\n if ((document as any).querySelector) {\n if (routerState.location.hash !== '') {\n const el = document.getElementById(\n routerState.location.hash,\n ) as HTMLElement | null\n if (el) {\n el.scrollIntoView()\n }\n }\n }\n\n router.__store.setState((s) => ({\n ...s,\n isTransitioning: false,\n resolvedLocation: s.location,\n }))\n }\n }, [\n routerState.isTransitioning,\n isTransitioning,\n routerState.isLoading,\n routerState.resolvedLocation,\n routerState.location,\n ])\n\n useLayoutEffect(() => {\n if (\n window.__TSR_DEHYDRATED__ ||\n (mountLoadForRouter.current.router === router &&\n mountLoadForRouter.current.mounted)\n ) {\n return\n }\n mountLoadForRouter.current = { router, mounted: true }\n tryLoad()\n }, [router])\n\n return null\n}\n\nexport function getRouteMatch<TRouteTree extends AnyRoute>(\n state: RouterState<TRouteTree>,\n id: string,\n): undefined | RouteMatch<TRouteTree> {\n return [\n ...state.cachedMatches,\n ...(state.pendingMatches ?? []),\n ...state.matches,\n ].find((d) => d.id === id)\n}\n\nexport type RouterProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {\n router: Router<TRouteTree>\n context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>\n}\n"],"names":[],"mappings":";;;;;;;AAcA,MAAM,gBACJ,MAAM,kBACL,MAAM;AAAA,EACL;AAAA,EACA,CAAC,OAAO;AACH;EACL;AACF;AAsCK,SAAS,eAGd,EAAE,QAAQ,GAAG,QAA8C;AAE3D,SAAO,OAAO;AAAA,IACZ,GAAG,OAAO;AAAA,IACV,GAAG;AAAA,IACH,SAAS;AAAA,MACP,GAAG,OAAO,QAAQ;AAAA,MAClB,GAAG,6BAAM;AAAA,IACX;AAAA,EAAA,CACM;AAER,QAAM,UAAU,OAAO,QAAQ,gCAC5B,OAAO,QAAQ,WAAf,EACC,UAAC,oBAAA,SAAA,EAAQ,EACX,CAAA,wBAEC,SAAQ,CAAA,CAAA;AAGX,QAAM,gBAAgB;AAEtB,QAAM,WACH,qBAAA,cAAc,UAAd,EAAuB,OAAO,QAC5B,UAAA;AAAA,IAAA;AAAA,wBACA,cAAa,EAAA;AAAA,EAChB,EAAA,CAAA;AAGE,MAAA,OAAO,QAAQ,MAAM;AACvB,WAAQ,oBAAA,OAAO,QAAQ,MAAf,EAAqB,UAAS,SAAA,CAAA;AAAA,EACxC;AAEO,SAAA;AACT;AAEA,SAAS,eAAe;AACtB,QAAM,SAAS;AACf,QAAM,qBAAqB,MAAM,OAAO,EAAE,QAAQ,SAAS,OAAO;AAClE,QAAM,cAAc,eAAe;AAAA,IACjC,QAAQ,CAAC,MACP,KAAK,GAAG,CAAC,aAAa,YAAY,oBAAoB,iBAAiB,CAAC;AAAA,EAAA,CAC3E;AAED,QAAM,CAAC,iBAAiB,oBAAoB,IAAI,cAAc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AAC,OAAO;AAAA,QAC9B,GAAG;AAAA,QACH,iBAAiB;AAAA,QACjB,kBAAkB,EAAE;AAAA,MACpB,EAAA;AAAA,IACJ;AAAA,EAAA,GACC;AAAA,IACD,YAAY;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,YAAY;AAAA,EAAA,CACb;AAED,kBAAgB,MAAM;AAElB,QAAA,OAAO,sBACN,mBAAmB,QAAQ,WAAW,UACrC,mBAAmB,QAAQ,SAC7B;AACA;AAAA,IACF;AACA,uBAAmB,UAAU,EAAE,QAAQ,SAAS,KAAK;AAC7C;EAAA,GACP,CAAC,MAAM,CAAC;AAEJ,SAAA;AACT;AAEgB,SAAA,cACd,OACA,IACoC;AAC7B,SAAA;AAAA,IACL,GAAG,MAAM;AAAA,IACT,GAAI,MAAM,kBAAkB,CAAC;AAAA,IAC7B,GAAG,MAAM;AAAA,EAAA,EACT,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE;AAC3B;"}
@@ -1,12 +1,10 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import { useRouter } from "./useRouter.js";
4
+ import { defaultSerializeError } from "./router.js";
4
5
  import { isDehydratedDeferred } from "./defer.js";
5
- import warning from "tiny-warning";
6
- import "@tanstack/history";
7
- import "tiny-invariant";
8
6
  import { isServerSideError, defaultDeserializeError } from "./Matches.js";
9
- import { defaultSerializeError } from "./router.js";
7
+ import warning from "tiny-warning";
10
8
  function useAwaited({ promise }) {
11
9
  var _a, _b;
12
10
  const router = useRouter();
@@ -1 +1 @@
1
- {"version":3,"file":"awaited.js","sources":["../../src/awaited.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport { DeferredPromise, isDehydratedDeferred } from './defer'\nimport warning from 'tiny-warning'\nimport {\n isServerSideError,\n defaultDeserializeError,\n defaultSerializeError,\n} from '.'\n\nexport type AwaitOptions<T> = {\n promise: DeferredPromise<T>\n}\n\nexport function useAwaited<T>({ promise }: AwaitOptions<T>): [T] {\n const router = useRouter()\n // const rerender = React.useReducer((x) => x + 1, 0)[1]\n\n const state = promise.__deferredState\n\n // Dehydrated promises only\n // Successful or errored deferred promises mean they\n // were resolved on the server and no further action is needed\n if (isDehydratedDeferred(promise) && state.status === 'pending') {\n const streamedData = (window as any)[`__TSR__DEFERRED__${state.uid}`]\n\n if (streamedData) {\n Object.assign(state, streamedData)\n } else {\n let token = router.registeredDeferredsIds.get(state.uid)\n\n // If we haven't yet, create a promise and resolver that our streamed HTML can use\n // when the client-side data is streamed in and ready.\n if (!token) {\n token = {}\n router.registeredDeferredsIds.set(state.uid, token)\n router.registeredDeferreds.set(token, state)\n\n Object.assign(state, {\n resolve: () => {\n state.__resolvePromise?.()\n // rerender()\n },\n promise: new Promise((r) => {\n state.__resolvePromise = r as any\n }),\n __resolvePromise: () => {},\n })\n }\n }\n }\n\n // If the promise is pending, always throw the state.promise\n // For originating promises, this will be the original promise\n // For dehydrated promises, this will be the placeholder promise\n // that will be resolved when the server sends the real data\n if (state.status === 'pending') {\n throw isDehydratedDeferred(promise) ? state.promise : promise\n }\n\n // If we are the originator of the promise,\n // inject the state into the HTML stream\n if (!isDehydratedDeferred(promise)) {\n router.injectHtml(`<script class='tsr_deferred_data'>window.__TSR__DEFERRED__${state.uid} = ${router.options.transformer.stringify(state)}</script>\n<script class='tsr_deferred_handler'>\n if (window.__TSR__ROUTER__) {\n let deferred = window.__TSR__ROUTER__.getDeferred('${state.uid}')\n if (deferred) deferred.resolve(window.__TSR__DEFERRED__${state.uid})\n }\n document.querySelectorAll('.tsr_deferred_handler').forEach((el) => el.parentElement.removeChild(el))\n</script>`)\n }\n\n if (state.status === 'error') {\n if (typeof document !== 'undefined') {\n if (isServerSideError(state.error)) {\n throw (\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n )(state.error.data as any)\n } else {\n warning(\n false,\n \"Encountered a server-side error that doesn't fit the expected shape\",\n )\n throw state.error\n }\n } else {\n throw {\n data: (\n router.options.errorSerializer?.serialize ?? defaultSerializeError\n )(state.error),\n __isServerError: true,\n }\n }\n }\n\n return [promise.__deferredState.data as any]\n}\n\nexport function Await<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n) {\n const inner = <AwaitInner {...props} />\n if (props.fallback) {\n return <React.Suspense fallback={props.fallback}>{inner}</React.Suspense>\n }\n return inner\n}\n\nfunction AwaitInner<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n) {\n const awaited = useAwaited(props)\n return props.children(...awaited)\n}\n"],"names":["_a"],"mappings":";;;;;;;;;AAcgB,SAAA,WAAc,EAAE,WAAiC;;AAC/D,QAAM,SAAS;AAGf,QAAM,QAAQ,QAAQ;AAKtB,MAAI,qBAAqB,OAAO,KAAK,MAAM,WAAW,WAAW;AAC/D,UAAM,eAAgB,OAAe,oBAAoB,MAAM,GAAG,EAAE;AAEpE,QAAI,cAAc;AACT,aAAA,OAAO,OAAO,YAAY;AAAA,IAAA,OAC5B;AACL,UAAI,QAAQ,OAAO,uBAAuB,IAAI,MAAM,GAAG;AAIvD,UAAI,CAAC,OAAO;AACV,gBAAQ,CAAA;AACR,eAAO,uBAAuB,IAAI,MAAM,KAAK,KAAK;AAC3C,eAAA,oBAAoB,IAAI,OAAO,KAAK;AAE3C,eAAO,OAAO,OAAO;AAAA,UACnB,SAAS,MAAM;;AACb,aAAAA,MAAA,MAAM,qBAAN,gBAAAA,IAAA;AAAA,UAEF;AAAA,UACA,SAAS,IAAI,QAAQ,CAAC,MAAM;AAC1B,kBAAM,mBAAmB;AAAA,UAAA,CAC1B;AAAA,UACD,kBAAkB,MAAM;AAAA,UAAC;AAAA,QAAA,CAC1B;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAMI,MAAA,MAAM,WAAW,WAAW;AAC9B,UAAM,qBAAqB,OAAO,IAAI,MAAM,UAAU;AAAA,EACxD;AAII,MAAA,CAAC,qBAAqB,OAAO,GAAG;AAC3B,WAAA,WAAW,6DAA6D,MAAM,GAAG,MAAM,OAAO,QAAQ,YAAY,UAAU,KAAK,CAAC;AAAA;AAAA;AAAA,yDAGpF,MAAM,GAAG;AAAA,6DACL,MAAM,GAAG;AAAA;AAAA;AAAA,WAG5D;AAAA,EACR;AAEI,MAAA,MAAM,WAAW,SAAS;AACxB,QAAA,OAAO,aAAa,aAAa;AAC/B,UAAA,kBAAkB,MAAM,KAAK,GAAG;AAClC,iBACE,YAAO,QAAQ,oBAAf,mBAAgC,gBAAe,yBAC/C,MAAM,MAAM,IAAW;AAAA,MAAA,OACpB;AACL;AAAA,UACE;AAAA,UACA;AAAA,QAAA;AAEF,cAAM,MAAM;AAAA,MACd;AAAA,IAAA,OACK;AACC,YAAA;AAAA,QACJ,SACE,YAAO,QAAQ,oBAAf,mBAAgC,cAAa,uBAC7C,MAAM,KAAK;AAAA,QACb,iBAAiB;AAAA,MAAA;AAAA,IAErB;AAAA,EACF;AAEO,SAAA,CAAC,QAAQ,gBAAgB,IAAW;AAC7C;AAEO,SAAS,MACd,OAIA;AACA,QAAM,QAAQ,oBAAC,YAAY,EAAA,GAAG,MAAO,CAAA;AACrC,MAAI,MAAM,UAAU;AAClB,+BAAQ,MAAM,UAAN,EAAe,UAAU,MAAM,UAAW,UAAM,MAAA,CAAA;AAAA,EAC1D;AACO,SAAA;AACT;AAEA,SAAS,WACP,OAIA;AACM,QAAA,UAAU,WAAW,KAAK;AACzB,SAAA,MAAM,SAAS,GAAG,OAAO;AAClC;"}
1
+ {"version":3,"file":"awaited.js","sources":["../../src/awaited.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport { defaultSerializeError } from './router'\nimport { DeferredPromise, isDehydratedDeferred } from './defer'\nimport { defaultDeserializeError, isServerSideError } from './Matches'\n\nimport warning from 'tiny-warning'\n\nexport type AwaitOptions<T> = {\n promise: DeferredPromise<T>\n}\n\nexport function useAwaited<T>({ promise }: AwaitOptions<T>): [T] {\n const router = useRouter()\n // const rerender = React.useReducer((x) => x + 1, 0)[1]\n\n const state = promise.__deferredState\n\n // Dehydrated promises only\n // Successful or errored deferred promises mean they\n // were resolved on the server and no further action is needed\n if (isDehydratedDeferred(promise) && state.status === 'pending') {\n const streamedData = (window as any)[`__TSR__DEFERRED__${state.uid}`]\n\n if (streamedData) {\n Object.assign(state, streamedData)\n } else {\n let token = router.registeredDeferredsIds.get(state.uid)\n\n // If we haven't yet, create a promise and resolver that our streamed HTML can use\n // when the client-side data is streamed in and ready.\n if (!token) {\n token = {}\n router.registeredDeferredsIds.set(state.uid, token)\n router.registeredDeferreds.set(token, state)\n\n Object.assign(state, {\n resolve: () => {\n state.__resolvePromise?.()\n // rerender()\n },\n promise: new Promise((r) => {\n state.__resolvePromise = r as any\n }),\n __resolvePromise: () => {},\n })\n }\n }\n }\n\n // If the promise is pending, always throw the state.promise\n // For originating promises, this will be the original promise\n // For dehydrated promises, this will be the placeholder promise\n // that will be resolved when the server sends the real data\n if (state.status === 'pending') {\n throw isDehydratedDeferred(promise) ? state.promise : promise\n }\n\n // If we are the originator of the promise,\n // inject the state into the HTML stream\n if (!isDehydratedDeferred(promise)) {\n router.injectHtml(`<script class='tsr_deferred_data'>window.__TSR__DEFERRED__${state.uid} = ${router.options.transformer.stringify(state)}</script>\n<script class='tsr_deferred_handler'>\n if (window.__TSR__ROUTER__) {\n let deferred = window.__TSR__ROUTER__.getDeferred('${state.uid}')\n if (deferred) deferred.resolve(window.__TSR__DEFERRED__${state.uid})\n }\n document.querySelectorAll('.tsr_deferred_handler').forEach((el) => el.parentElement.removeChild(el))\n</script>`)\n }\n\n if (state.status === 'error') {\n if (typeof document !== 'undefined') {\n if (isServerSideError(state.error)) {\n throw (\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n )(state.error.data as any)\n } else {\n warning(\n false,\n \"Encountered a server-side error that doesn't fit the expected shape\",\n )\n throw state.error\n }\n } else {\n throw {\n data: (\n router.options.errorSerializer?.serialize ?? defaultSerializeError\n )(state.error),\n __isServerError: true,\n }\n }\n }\n\n return [promise.__deferredState.data as any]\n}\n\nexport function Await<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n) {\n const inner = <AwaitInner {...props} />\n if (props.fallback) {\n return <React.Suspense fallback={props.fallback}>{inner}</React.Suspense>\n }\n return inner\n}\n\nfunction AwaitInner<T>(\n props: AwaitOptions<T> & {\n fallback?: React.ReactNode\n children: (result: T) => React.ReactNode\n },\n) {\n const awaited = useAwaited(props)\n return props.children(...awaited)\n}\n"],"names":["_a"],"mappings":";;;;;;;AAYgB,SAAA,WAAc,EAAE,WAAiC;;AAC/D,QAAM,SAAS;AAGf,QAAM,QAAQ,QAAQ;AAKtB,MAAI,qBAAqB,OAAO,KAAK,MAAM,WAAW,WAAW;AAC/D,UAAM,eAAgB,OAAe,oBAAoB,MAAM,GAAG,EAAE;AAEpE,QAAI,cAAc;AACT,aAAA,OAAO,OAAO,YAAY;AAAA,IAAA,OAC5B;AACL,UAAI,QAAQ,OAAO,uBAAuB,IAAI,MAAM,GAAG;AAIvD,UAAI,CAAC,OAAO;AACV,gBAAQ,CAAA;AACR,eAAO,uBAAuB,IAAI,MAAM,KAAK,KAAK;AAC3C,eAAA,oBAAoB,IAAI,OAAO,KAAK;AAE3C,eAAO,OAAO,OAAO;AAAA,UACnB,SAAS,MAAM;;AACb,aAAAA,MAAA,MAAM,qBAAN,gBAAAA,IAAA;AAAA,UAEF;AAAA,UACA,SAAS,IAAI,QAAQ,CAAC,MAAM;AAC1B,kBAAM,mBAAmB;AAAA,UAAA,CAC1B;AAAA,UACD,kBAAkB,MAAM;AAAA,UAAC;AAAA,QAAA,CAC1B;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAMI,MAAA,MAAM,WAAW,WAAW;AAC9B,UAAM,qBAAqB,OAAO,IAAI,MAAM,UAAU;AAAA,EACxD;AAII,MAAA,CAAC,qBAAqB,OAAO,GAAG;AAC3B,WAAA,WAAW,6DAA6D,MAAM,GAAG,MAAM,OAAO,QAAQ,YAAY,UAAU,KAAK,CAAC;AAAA;AAAA;AAAA,yDAGpF,MAAM,GAAG;AAAA,6DACL,MAAM,GAAG;AAAA;AAAA;AAAA,WAG5D;AAAA,EACR;AAEI,MAAA,MAAM,WAAW,SAAS;AACxB,QAAA,OAAO,aAAa,aAAa;AAC/B,UAAA,kBAAkB,MAAM,KAAK,GAAG;AAClC,iBACE,YAAO,QAAQ,oBAAf,mBAAgC,gBAAe,yBAC/C,MAAM,MAAM,IAAW;AAAA,MAAA,OACpB;AACL;AAAA,UACE;AAAA,UACA;AAAA,QAAA;AAEF,cAAM,MAAM;AAAA,MACd;AAAA,IAAA,OACK;AACC,YAAA;AAAA,QACJ,SACE,YAAO,QAAQ,oBAAf,mBAAgC,cAAa,uBAC7C,MAAM,KAAK;AAAA,QACb,iBAAiB;AAAA,MAAA;AAAA,IAErB;AAAA,EACF;AAEO,SAAA,CAAC,QAAQ,gBAAgB,IAAW;AAC7C;AAEO,SAAS,MACd,OAIA;AACA,QAAM,QAAQ,oBAAC,YAAY,EAAA,GAAG,MAAO,CAAA;AACrC,MAAI,MAAM,UAAU;AAClB,+BAAQ,MAAM,UAAN,EAAe,UAAU,MAAM,UAAW,UAAM,MAAA,CAAA;AAAA,EAC1D;AACO,SAAA;AACT;AAEA,SAAS,WACP,OAIA;AACM,QAAA,UAAU,WAAW,KAAK;AACzB,SAAA,MAAM,SAAS,GAAG,OAAO;AAClC;"}
@@ -4,7 +4,8 @@ import { ParsePathParams } from './link.js';
4
4
  import { AnyRoute, ResolveFullPath, ResolveFullSearchSchema, MergeFromFromParent, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, RootRouteId, TrimPathLeft, RouteConstraints, ResolveFullSearchSchemaInput, SearchSchemaInput, RouteLoaderFn, AnyPathParams, AnySearchSchema } from './route.js';
5
5
  import { Assign, Expand, IsAny } from './utils.js';
6
6
  import { RouteMatch } from './Matches.js';
7
- import { RegisteredRouter, RouteById, RouteIds } from '.';
7
+ import { RegisteredRouter } from './router.js';
8
+ import { RouteById, RouteIds } from './routeInfo.js';
8
9
  export interface FileRoutesByPath {
9
10
  }
10
11
  type Replace<S extends string, From extends string, To extends string> = S extends `${infer Start}${From}${infer Rest}` ? `${Start}${To}${Replace<Rest, From, To>}` : S;
@@ -17,7 +18,7 @@ type NormalizeSlashes<S extends string> = S extends `${infer Before}//${infer Af
17
18
  type ReplaceFirstOccurrence<T extends string, Search extends string, Replacement extends string> = T extends `${infer Prefix}${Search}${infer Suffix}` ? `${Prefix}${Replacement}${Suffix}` : T;
18
19
  export type ResolveFilePath<TParentRoute extends AnyRoute, TFilePath extends string> = TParentRoute['id'] extends RootRouteId ? TrimPathLeft<TFilePath> : ReplaceFirstOccurrence<TrimPathLeft<TFilePath>, TrimPathLeft<TParentRoute['types']['customId']>, ''>;
19
20
  export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends string> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}` ? '' : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}` ? '' : ResolveFilePath<TParentRoute, TFilePath>;
20
- export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = NormalizeSlashes<RemoveRouteGroups<TFilePath>>, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, NormalizeSlashes<RemoveRouteGroups<RemoveUnderScores<TPath>>>>>(path: TFilePath): <TSearchSchemaInput extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, "__TSearchSchemaInput__"> : TSearchSchema, TFullSearchSchemaInput extends AnySearchSchema = Expand<Assign<Omit<import("./route").InferFullSearchSchemaInput<TParentRoute>, "__TRootSearchSchema__">, TSearchSchemaUsed>>, TFullSearchSchema extends AnySearchSchema = Expand<Assign<Omit<import("./route").InferFullSearchSchema<TParentRoute>, "__TRootSearchSchema__">, TSearchSchema>>, TParams extends Record<string, any> = Expand<Record<TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L extends "" ? "_splat" : L : never : never : never, string>>, TAllParams extends Record<string, any> = IsAny<TParentRoute["types"]["allParams"], TParams, TParentRoute["types"]["allParams"] & TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute"> & {
21
+ export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = NormalizeSlashes<RemoveRouteGroups<TFilePath>>, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, NormalizeSlashes<RemoveRouteGroups<RemoveUnderScores<TPath>>>>>(path: TFilePath): <TSearchSchemaInput extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, "__TSearchSchemaInput__"> : TSearchSchema, TFullSearchSchemaInput extends AnySearchSchema = Expand<Assign<Omit<import("./route").InferFullSearchSchemaInput<TParentRoute>, "__TRootSearchSchema__">, TSearchSchemaUsed>>, TFullSearchSchema extends AnySearchSchema = Expand<Assign<Omit<import("./route").InferFullSearchSchema<TParentRoute>, "__TRootSearchSchema__">, TSearchSchema>>, TParams extends Record<string, any> = Expand<Record<TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L extends "" ? "_splat" : L : never : never : never, string>>, TAllParams extends Record<string, any> = IsAny<TParentRoute["types"]["allParams"], TParams, TParentRoute["types"]["allParams"] & TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn extends unknown = unknown, TLoaderData extends unknown = [TLoaderDataReturn] extends [never] ? undefined : TLoaderDataReturn, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>, "path" | "id" | "getParentRoute"> & {
21
22
  caseSensitive?: boolean | undefined;
22
23
  wrapInSuspense?: boolean | undefined;
23
24
  component?: import("./route").RouteComponent<any> | undefined;
@@ -47,7 +48,7 @@ export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath
47
48
  }) => Record<string, string> | Promise<Record<string, string>>) | undefined;
48
49
  } & {
49
50
  staticData?: import("./route").StaticDataRouteOption | undefined;
50
- }) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree>;
51
+ }) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TChildren, TRouteTree>;
51
52
  /**
52
53
  @deprecated It's no longer recommended to use the `FileRoute` class directly.
53
54
  Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
@@ -58,7 +59,7 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
58
59
  constructor(path: TFilePath, _opts?: {
59
60
  silent: boolean;
60
61
  });
61
- createRoute: <TSearchSchemaInput extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, "__TSearchSchemaInput__"> : TSearchSchema, TFullSearchSchemaInput extends AnySearchSchema = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema extends AnySearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends Record<string, any> = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends Record<string, any> = MergeFromFromParent<TParentRoute["types"]["allParams"], TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute"> & {
62
+ createRoute: <TSearchSchemaInput extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, "__TSearchSchemaInput__"> : TSearchSchema, TFullSearchSchemaInput extends AnySearchSchema = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema extends AnySearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends Record<string, any> = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends Record<string, any> = MergeFromFromParent<TParentRoute["types"]["allParams"], TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn extends unknown = unknown, TLoaderData extends unknown = [TLoaderDataReturn] extends [never] ? undefined : TLoaderDataReturn, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>, "path" | "id" | "getParentRoute"> & {
62
63
  caseSensitive?: boolean | undefined;
63
64
  wrapInSuspense?: boolean | undefined;
64
65
  component?: import("./route").RouteComponent<any> | undefined;
@@ -88,7 +89,7 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
88
89
  }) => Record<string, string> | Promise<Record<string, string>>) | undefined;
89
90
  } & {
90
91
  staticData?: import("./route").StaticDataRouteOption | undefined;
91
- }) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree>;
92
+ }) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TChildren, TRouteTree>;
92
93
  }
93
94
  /**
94
95
  @deprecated It's recommended not to split loaders into separate files.
@@ -124,5 +125,5 @@ export declare class LazyRoute<TRoute extends AnyRoute> {
124
125
  } | undefined) => TSelected;
125
126
  }
126
127
  export declare function createLazyRoute<TId extends RouteIds<RegisteredRouter['routeTree']>, TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>>(id: TId): (opts: LazyRouteOptions) => LazyRoute<TRoute>;
127
- export declare function createLazyFileRoute<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute>;
128
+ export declare function createLazyFileRoute<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(path: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute>;
128
129
  export {};
@@ -62,9 +62,14 @@ function createLazyRoute(id) {
62
62
  return new LazyRoute({ id, ...opts });
63
63
  };
64
64
  }
65
- function createLazyFileRoute(id) {
65
+ function createLazyFileRoute(path) {
66
+ const id = removeGroups(path);
66
67
  return (opts) => new LazyRoute({ id, ...opts });
67
68
  }
69
+ const routeGroupPatternRegex = /\(.+\)/g;
70
+ function removeGroups(s) {
71
+ return s.replaceAll(routeGroupPatternRegex, "").replaceAll("//", "/");
72
+ }
68
73
  export {
69
74
  FileRoute,
70
75
  FileRouteLoader,
@@ -1 +1 @@
1
- {"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { NoInfer } from '@tanstack/react-store'\nimport { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n ResolveFullSearchSchema,\n MergeFromFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n UpdatableRouteOptions,\n Route,\n createRoute,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n ResolveFullSearchSchemaInput,\n SearchSchemaInput,\n LoaderFnContext,\n RouteLoaderFn,\n AnyPathParams,\n AnySearchSchema,\n} from './route'\nimport { Assign, Expand, IsAny } from './utils'\nimport { useMatch, useLoaderDeps, useLoaderData, RouteMatch } from './Matches'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport warning from 'tiny-warning'\nimport { RegisteredRouter, RouteById, RouteIds } from '.'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\ntype RemoveRouteGroups<S extends string> =\n S extends `${infer Before}(${infer RouteGroup})${infer After}`\n ? RemoveRouteGroups<`${Before}${After}`>\n : S\n\ntype NormalizeSlashes<S extends string> =\n S extends `${infer Before}//${infer After}`\n ? NormalizeSlashes<`${Before}/${After}`>\n : S\n\ntype ReplaceFirstOccurrence<\n T extends string,\n Search extends string,\n Replacement extends string,\n> = T extends `${infer Prefix}${Search}${infer Suffix}`\n ? `${Prefix}${Replacement}${Suffix}`\n : T\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : ReplaceFirstOccurrence<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> =\n ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = NormalizeSlashes<\n RemoveRouteGroups<TFilePath>\n >,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n NormalizeSlashes<RemoveRouteGroups<RemoveUnderScores<TPath>>>\n >,\n>(path: TFilePath) {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n silent?: boolean\n\n constructor(\n public path: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchemaUsed extends Record<\n string,\n any\n > = TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : TSearchSchema,\n TFullSearchSchemaInput extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchSchemaUsed\n >,\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<\n TParentRoute['types']['allParams'],\n TParams\n >,\n TRouteContextReturn extends\n RouteConstraints['TRouteContext'] = RouteContext,\n TRouteContext extends RouteConstraints['TRouteContext'] = [\n TRouteContextReturn,\n ] extends [never]\n ? RouteContext\n : TRouteContextReturn,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options?: Omit<\n RouteOptions<\n TParentRoute,\n string,\n TPath,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions<TAllParams, TFullSearchSchema, TLoaderData>,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderData,\n TChildren,\n TRouteTree\n > => {\n warning(\n this.silent,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/** \n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the the main route file, inside the\n `createFileRoute('/path/to/file)(options)` options.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderData extends any>(\n loaderFn: RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n TLoaderData\n >,\n) => RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n NoInfer<TLoaderData>\n> {\n warning(\n false,\n `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n return (loaderFn) => loaderFn\n}\n\nexport type LazyRouteOptions = Pick<\n UpdatableRouteOptions<AnyPathParams, AnySearchSchema, any>,\n 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'\n>\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n useMatch = <\n TRouteMatchState = RouteMatch<\n TRoute['types']['routeTree'],\n TRoute['types']['id']\n >,\n TSelected = TRouteMatchState,\n >(opts?: {\n select?: (match: TRouteMatchState) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.options.id })\n }\n\n useRouteContext = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.options.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = TRoute['types']['fullSearchSchema']>(opts?: {\n select?: (s: TRoute['types']['fullSearchSchema']) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.options.id })\n }\n\n useParams = <TSelected = TRoute['types']['allParams']>(opts?: {\n select?: (s: TRoute['types']['allParams']) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.options.id })\n }\n\n useLoaderDeps = <TSelected = TRoute['types']['loaderDeps']>(opts?: {\n select?: (s: TRoute['types']['loaderDeps']) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData = <TSelected = TRoute['types']['loaderData']>(opts?: {\n select?: (s: TRoute['types']['loaderData']) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n}\n\nexport function createLazyRoute<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n>(id: TId) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({ id: id as any, ...opts })\n }\n}\n\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(id: TFilePath) {\n return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })\n}\n"],"names":["opts"],"mappings":";;;;;AAwGO,SAAS,gBAcd,MAAiB;AACV,SAAA,IAAI,UAA0D,MAAM;AAAA,IACzE,QAAQ;AAAA,EACT,CAAA,EAAE;AACL;AAMO,MAAM,UAYX;AAAA,EAGA,YACS,MACP,OACA;AAFO,SAAA,OAAA;AAMT,SAAA,cAAc,CA4CZ,YA2CG;AACH;AAAA,QACE,KAAK;AAAA,QACL;AAAA,MAAA;AAEI,YAAA,QAAQ,YAAY,OAAc;AACtC,YAAc,SAAS;AAClB,aAAA;AAAA,IAAA;AAjGP,SAAK,SAAS,+BAAO;AAAA,EACvB;AAkGF;AAOO,SAAS,gBAId,OAeA;AACA;AAAA,IACE;AAAA,IACA;AAAA,EAAA;AAEF,SAAO,CAAC,aAAa;AACvB;AAOO,MAAM,UAAmC;AAAA,EAK9C,YACE,MAGA;AAKF,SAAA,WAAW,CAMTA,UAEe;AACR,aAAA,SAAS,EAAE,QAAQA,SAAA,gBAAAA,MAAM,QAAQ,MAAM,KAAK,QAAQ,GAAA,CAAI;AAAA,IAAA;AAGjE,SAAA,kBAAkB,CAA4CA,UAE7C;AACf,aAAO,SAAS;AAAA,QACd,MAAM,KAAK,QAAQ;AAAA,QACnB,QAAQ,CAAC,OAAYA,SAAA,gBAAAA,MAAM,UAASA,MAAK,OAAO,EAAE,OAAO,IAAI,EAAE;AAAA,MAAA,CAChE;AAAA,IAAA;AAGH,SAAA,YAAY,CAAkDA,UAE7C;AACR,aAAA,UAAU,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAGrD,SAAA,YAAY,CAA2CA,UAEtC;AACR,aAAA,UAAU,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAGrD,SAAA,gBAAgB,CAA4CA,UAE3C;AACR,aAAA,cAAc,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAW;AAAA,IAAA;AAGhE,SAAA,gBAAgB,CAA4CA,UAE3C;AACR,aAAA,cAAc,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAW;AAAA,IAAA;AA9C9D,SAAK,UAAU;AACb,SAAa,WAAW,OAAO,IAAI,YAAY;AAAA,EACnD;AA8CF;AAEO,SAAS,gBAGd,IAAS;AACT,SAAO,CAAC,SAA2B;AACjC,WAAO,IAAI,UAAkB,EAAE,IAAe,GAAG,KAAM,CAAA;AAAA,EAAA;AAE3D;AAEO,SAAS,oBAGd,IAAe;AACR,SAAA,CAAC,SAA2B,IAAI,UAAkB,EAAE,IAAI,GAAG,MAAM;AAC1E;"}
1
+ {"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { NoInfer } from '@tanstack/react-store'\nimport { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n ResolveFullSearchSchema,\n MergeFromFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n UpdatableRouteOptions,\n Route,\n createRoute,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n ResolveFullSearchSchemaInput,\n SearchSchemaInput,\n RouteLoaderFn,\n AnyPathParams,\n AnySearchSchema,\n} from './route'\nimport { Assign, Expand, IsAny } from './utils'\nimport { useMatch, useLoaderDeps, useLoaderData, RouteMatch } from './Matches'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport warning from 'tiny-warning'\nimport { RegisteredRouter } from './router'\nimport { RouteById, RouteIds } from './routeInfo'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\ntype RemoveRouteGroups<S extends string> =\n S extends `${infer Before}(${infer RouteGroup})${infer After}`\n ? RemoveRouteGroups<`${Before}${After}`>\n : S\n\ntype NormalizeSlashes<S extends string> =\n S extends `${infer Before}//${infer After}`\n ? NormalizeSlashes<`${Before}/${After}`>\n : S\n\ntype ReplaceFirstOccurrence<\n T extends string,\n Search extends string,\n Replacement extends string,\n> = T extends `${infer Prefix}${Search}${infer Suffix}`\n ? `${Prefix}${Replacement}${Suffix}`\n : T\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : ReplaceFirstOccurrence<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> =\n ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = NormalizeSlashes<\n RemoveRouteGroups<TFilePath>\n >,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n NormalizeSlashes<RemoveRouteGroups<RemoveUnderScores<TPath>>>\n >,\n>(path: TFilePath) {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n silent?: boolean\n\n constructor(\n public path: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchemaUsed extends Record<\n string,\n any\n > = TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : TSearchSchema,\n TFullSearchSchemaInput extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchSchemaUsed\n >,\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<\n TParentRoute['types']['allParams'],\n TParams\n >,\n TRouteContextReturn extends\n RouteConstraints['TRouteContext'] = RouteContext,\n TRouteContext extends RouteConstraints['TRouteContext'] = [\n TRouteContextReturn,\n ] extends [never]\n ? RouteContext\n : TRouteContextReturn,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn extends any = unknown,\n TLoaderData extends any = [TLoaderDataReturn] extends [never]\n ? undefined\n : TLoaderDataReturn,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options?: Omit<\n RouteOptions<\n TParentRoute,\n string,\n TPath,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions<TAllParams, TFullSearchSchema, TLoaderData>,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren,\n TRouteTree\n > => {\n warning(\n this.silent,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/** \n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the the main route file, inside the\n `createFileRoute('/path/to/file)(options)` options.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderData extends any>(\n loaderFn: RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n TLoaderData\n >,\n) => RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n NoInfer<TLoaderData>\n> {\n warning(\n false,\n `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n return (loaderFn) => loaderFn\n}\n\nexport type LazyRouteOptions = Pick<\n UpdatableRouteOptions<AnyPathParams, AnySearchSchema, any>,\n 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'\n>\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n useMatch = <\n TRouteMatchState = RouteMatch<\n TRoute['types']['routeTree'],\n TRoute['types']['id']\n >,\n TSelected = TRouteMatchState,\n >(opts?: {\n select?: (match: TRouteMatchState) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.options.id })\n }\n\n useRouteContext = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.options.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = TRoute['types']['fullSearchSchema']>(opts?: {\n select?: (s: TRoute['types']['fullSearchSchema']) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.options.id })\n }\n\n useParams = <TSelected = TRoute['types']['allParams']>(opts?: {\n select?: (s: TRoute['types']['allParams']) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.options.id })\n }\n\n useLoaderDeps = <TSelected = TRoute['types']['loaderDeps']>(opts?: {\n select?: (s: TRoute['types']['loaderDeps']) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData = <TSelected = TRoute['types']['loaderData']>(opts?: {\n select?: (s: TRoute['types']['loaderData']) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n}\n\nexport function createLazyRoute<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n>(id: TId) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({ id: id as any, ...opts })\n }\n}\n\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(path: TFilePath) {\n const id = removeGroups(path)\n return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })\n}\n\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')\n}\n"],"names":["opts"],"mappings":";;;;;AAwGO,SAAS,gBAcd,MAAiB;AACV,SAAA,IAAI,UAA0D,MAAM;AAAA,IACzE,QAAQ;AAAA,EACT,CAAA,EAAE;AACL;AAMO,MAAM,UAYX;AAAA,EAGA,YACS,MACP,OACA;AAFO,SAAA,OAAA;AAMT,SAAA,cAAc,CA+CZ,YA6CG;AACH;AAAA,QACE,KAAK;AAAA,QACL;AAAA,MAAA;AAEI,YAAA,QAAQ,YAAY,OAAc;AACtC,YAAc,SAAS;AAClB,aAA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