@tanstack/router-core 1.132.0-alpha.2 → 1.132.0-alpha.20

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 (142) hide show
  1. package/dist/cjs/Matches.cjs.map +1 -1
  2. package/dist/cjs/Matches.d.cts +2 -2
  3. package/dist/cjs/config.cjs +10 -0
  4. package/dist/cjs/config.cjs.map +1 -0
  5. package/dist/cjs/config.d.cts +17 -0
  6. package/dist/cjs/fileRoute.d.cts +3 -2
  7. package/dist/cjs/index.cjs +15 -3
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/index.d.cts +11 -4
  10. package/dist/cjs/load-matches.cjs +636 -0
  11. package/dist/cjs/load-matches.cjs.map +1 -0
  12. package/dist/cjs/load-matches.d.cts +16 -0
  13. package/dist/cjs/location.d.cts +38 -0
  14. package/dist/cjs/path.cjs +7 -49
  15. package/dist/cjs/path.cjs.map +1 -1
  16. package/dist/cjs/path.d.cts +3 -6
  17. package/dist/cjs/qss.cjs +19 -19
  18. package/dist/cjs/qss.cjs.map +1 -1
  19. package/dist/cjs/qss.d.cts +6 -4
  20. package/dist/cjs/redirect.cjs +3 -3
  21. package/dist/cjs/redirect.cjs.map +1 -1
  22. package/dist/cjs/rewrite.cjs +63 -0
  23. package/dist/cjs/rewrite.cjs.map +1 -0
  24. package/dist/cjs/rewrite.d.cts +22 -0
  25. package/dist/cjs/route.cjs.map +1 -1
  26. package/dist/cjs/route.d.cts +42 -37
  27. package/dist/cjs/router.cjs +134 -780
  28. package/dist/cjs/router.cjs.map +1 -1
  29. package/dist/cjs/router.d.cts +68 -36
  30. package/dist/cjs/scroll-restoration.cjs +32 -29
  31. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  32. package/dist/cjs/scroll-restoration.d.cts +1 -1
  33. package/dist/cjs/searchParams.cjs +7 -15
  34. package/dist/cjs/searchParams.cjs.map +1 -1
  35. package/dist/cjs/ssr/constants.cjs +5 -0
  36. package/dist/cjs/ssr/constants.cjs.map +1 -0
  37. package/dist/cjs/ssr/constants.d.cts +1 -0
  38. package/dist/cjs/ssr/{seroval-plugins.cjs → serializer/ShallowErrorPlugin.cjs} +2 -2
  39. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -0
  40. package/dist/cjs/ssr/{seroval-plugins.d.cts → serializer/ShallowErrorPlugin.d.cts} +1 -2
  41. package/dist/cjs/ssr/serializer/seroval-plugins.cjs +11 -0
  42. package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -0
  43. package/dist/cjs/ssr/serializer/seroval-plugins.d.cts +2 -0
  44. package/dist/cjs/ssr/serializer/transformer.cjs +52 -0
  45. package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -0
  46. package/dist/cjs/ssr/serializer/transformer.d.cts +56 -0
  47. package/dist/cjs/ssr/server.d.cts +5 -0
  48. package/dist/cjs/ssr/ssr-client.cjs +15 -1
  49. package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
  50. package/dist/cjs/ssr/ssr-client.d.cts +5 -1
  51. package/dist/cjs/ssr/ssr-server.cjs +12 -10
  52. package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
  53. package/dist/cjs/ssr/ssr-server.d.cts +0 -1
  54. package/dist/cjs/ssr/tsrScript.cjs +1 -1
  55. package/dist/cjs/ssr/tsrScript.cjs.map +1 -1
  56. package/dist/cjs/utils.cjs +8 -7
  57. package/dist/cjs/utils.cjs.map +1 -1
  58. package/dist/cjs/utils.d.cts +1 -1
  59. package/dist/esm/Matches.d.ts +2 -2
  60. package/dist/esm/Matches.js.map +1 -1
  61. package/dist/esm/config.d.ts +17 -0
  62. package/dist/esm/config.js +10 -0
  63. package/dist/esm/config.js.map +1 -0
  64. package/dist/esm/fileRoute.d.ts +3 -2
  65. package/dist/esm/index.d.ts +11 -4
  66. package/dist/esm/index.js +17 -5
  67. package/dist/esm/index.js.map +1 -1
  68. package/dist/esm/load-matches.d.ts +16 -0
  69. package/dist/esm/load-matches.js +636 -0
  70. package/dist/esm/load-matches.js.map +1 -0
  71. package/dist/esm/location.d.ts +38 -0
  72. package/dist/esm/path.d.ts +3 -6
  73. package/dist/esm/path.js +7 -49
  74. package/dist/esm/path.js.map +1 -1
  75. package/dist/esm/qss.d.ts +6 -4
  76. package/dist/esm/qss.js +19 -19
  77. package/dist/esm/qss.js.map +1 -1
  78. package/dist/esm/redirect.js +3 -3
  79. package/dist/esm/redirect.js.map +1 -1
  80. package/dist/esm/rewrite.d.ts +22 -0
  81. package/dist/esm/rewrite.js +63 -0
  82. package/dist/esm/rewrite.js.map +1 -0
  83. package/dist/esm/route.d.ts +42 -37
  84. package/dist/esm/route.js.map +1 -1
  85. package/dist/esm/router.d.ts +68 -36
  86. package/dist/esm/router.js +136 -782
  87. package/dist/esm/router.js.map +1 -1
  88. package/dist/esm/scroll-restoration.d.ts +1 -1
  89. package/dist/esm/scroll-restoration.js +32 -29
  90. package/dist/esm/scroll-restoration.js.map +1 -1
  91. package/dist/esm/searchParams.js +7 -15
  92. package/dist/esm/searchParams.js.map +1 -1
  93. package/dist/esm/ssr/constants.d.ts +1 -0
  94. package/dist/esm/ssr/constants.js +5 -0
  95. package/dist/esm/ssr/constants.js.map +1 -0
  96. package/dist/esm/ssr/{seroval-plugins.d.ts → serializer/ShallowErrorPlugin.d.ts} +1 -2
  97. package/dist/esm/ssr/{seroval-plugins.js → serializer/ShallowErrorPlugin.js} +2 -2
  98. package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -0
  99. package/dist/esm/ssr/serializer/seroval-plugins.d.ts +2 -0
  100. package/dist/esm/ssr/serializer/seroval-plugins.js +11 -0
  101. package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -0
  102. package/dist/esm/ssr/serializer/transformer.d.ts +56 -0
  103. package/dist/esm/ssr/serializer/transformer.js +52 -0
  104. package/dist/esm/ssr/serializer/transformer.js.map +1 -0
  105. package/dist/esm/ssr/server.d.ts +5 -0
  106. package/dist/esm/ssr/ssr-client.d.ts +5 -1
  107. package/dist/esm/ssr/ssr-client.js +15 -1
  108. package/dist/esm/ssr/ssr-client.js.map +1 -1
  109. package/dist/esm/ssr/ssr-server.d.ts +0 -1
  110. package/dist/esm/ssr/ssr-server.js +12 -10
  111. package/dist/esm/ssr/ssr-server.js.map +1 -1
  112. package/dist/esm/ssr/tsrScript.js +1 -1
  113. package/dist/esm/ssr/tsrScript.js.map +1 -1
  114. package/dist/esm/utils.d.ts +1 -1
  115. package/dist/esm/utils.js +8 -7
  116. package/dist/esm/utils.js.map +1 -1
  117. package/package.json +1 -1
  118. package/src/Matches.ts +2 -2
  119. package/src/config.ts +42 -0
  120. package/src/fileRoute.ts +15 -3
  121. package/src/index.ts +32 -3
  122. package/src/load-matches.ts +955 -0
  123. package/src/location.ts +38 -0
  124. package/src/path.ts +9 -66
  125. package/src/qss.ts +27 -24
  126. package/src/redirect.ts +3 -3
  127. package/src/rewrite.ts +70 -0
  128. package/src/route.ts +136 -33
  129. package/src/router.ts +271 -1170
  130. package/src/scroll-restoration.ts +42 -37
  131. package/src/searchParams.ts +8 -19
  132. package/src/ssr/constants.ts +1 -0
  133. package/src/ssr/{seroval-plugins.ts → serializer/ShallowErrorPlugin.ts} +2 -2
  134. package/src/ssr/serializer/seroval-plugins.ts +9 -0
  135. package/src/ssr/serializer/transformer.ts +215 -0
  136. package/src/ssr/server.ts +6 -0
  137. package/src/ssr/ssr-client.ts +30 -3
  138. package/src/ssr/ssr-server.ts +18 -10
  139. package/src/ssr/tsrScript.ts +5 -1
  140. package/src/utils.ts +11 -10
  141. package/dist/cjs/ssr/seroval-plugins.cjs.map +0 -1
  142. package/dist/esm/ssr/seroval-plugins.js.map +0 -1
@@ -1,17 +1,20 @@
1
1
  import { Store } from '@tanstack/store';
2
+ import { loadRouteChunk } from './load-matches.js';
2
3
  import { ParsePathnameCache } from './path.js';
3
4
  import { SearchParser, SearchSerializer } from './searchParams.js';
4
5
  import { AnyRedirect, ResolvedRedirect } from './redirect.js';
5
6
  import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
6
- import { Awaitable, ControlledPromise, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
7
+ import { Awaitable, Constrain, ControlledPromise, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
7
8
  import { ParsedLocation } from './location.js';
8
9
  import { AnyContext, AnyRoute, AnyRouteWithContext, MakeRemountDepsOptionsUnion, RouteMask } from './route.js';
9
10
  import { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.js';
10
- import { AnyRouteMatch, MakeRouteMatch, MakeRouteMatchUnion, MatchRouteOptions } from './Matches.js';
11
+ import { AnyRouteMatch, MakeRouteMatchUnion, MatchRouteOptions } from './Matches.js';
11
12
  import { BuildLocationFn, CommitLocationOptions, NavigateFn } from './RouterProvider.js';
12
13
  import { Manifest } from './manifest.js';
13
14
  import { AnySchema } from './validators.js';
14
15
  import { NavigateOptions, ResolveRelativePath, ToOptions } from './link.js';
16
+ import { AnySerializationAdapter, ValidateSerializableInput } from './ssr/serializer/transformer.js';
17
+ import { AnyRouterConfig } from './config.js';
15
18
  export type ControllablePromise<T = any> = Promise<T> & {
16
19
  resolve: (value: T) => void;
17
20
  reject: (value?: any) => void;
@@ -19,6 +22,8 @@ export type ControllablePromise<T = any> = Promise<T> & {
19
22
  export type InjectedHtmlEntry = Promise<string>;
20
23
  export interface DefaultRegister {
21
24
  router: AnyRouter;
25
+ config: AnyRouterConfig;
26
+ ssr: SSROption;
22
27
  }
23
28
  export interface Register extends DefaultRegister {
24
29
  }
@@ -28,7 +33,8 @@ export interface DefaultRouterOptionsExtensions {
28
33
  }
29
34
  export interface RouterOptionsExtensions extends DefaultRouterOptionsExtensions {
30
35
  }
31
- export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean = false, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated extends Record<string, any> = Record<string, any>> extends RouterOptionsExtensions {
36
+ export type SSROption = boolean | 'data-only';
37
+ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean = false, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated = undefined> extends RouterOptionsExtensions {
32
38
  /**
33
39
  * The history object that will be used to manage the browser history.
34
40
  *
@@ -172,6 +178,18 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
172
178
  /**
173
179
  * The basepath for then entire router. This is useful for mounting a router instance at a subpath.
174
180
  *
181
+ * @deprecated - use `rewrite.input` with the new `rewriteBasepath` utility instead:
182
+ * ```ts
183
+ * const router = createRouter({
184
+ * routeTree,
185
+ * rewrite: rewriteBasepath('/basepath')
186
+ * // Or wrap existing rewrite functionality
187
+ * rewrite: rewriteBasepath('/basepath', {
188
+ * output: ({ url }) => {...},
189
+ * input: ({ url }) => {...},
190
+ * })
191
+ * })
192
+ * ```
175
193
  * @default '/'
176
194
  * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#basepath-property)
177
195
  */
@@ -195,7 +213,7 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
195
213
  * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#dehydrate-method)
196
214
  * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading#critical-dehydrationhydration)
197
215
  */
198
- dehydrate?: () => Awaitable<TDehydrated>;
216
+ dehydrate?: () => Constrain<TDehydrated, ValidateSerializableInput<Register, TDehydrated>>;
199
217
  /**
200
218
  * A function that will be called when the router is hydrated.
201
219
  *
@@ -261,7 +279,7 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
261
279
  *
262
280
  * @default true
263
281
  */
264
- defaultSsr?: boolean | 'data-only';
282
+ defaultSsr?: SSROption;
265
283
  search?: {
266
284
  /**
267
285
  * Configures how unknown search params (= not returned by any `validateSearch`) are treated.
@@ -290,7 +308,9 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
290
308
  *
291
309
  * @default false
292
310
  */
293
- scrollRestoration?: boolean;
311
+ scrollRestoration?: boolean | ((opts: {
312
+ location: ParsedLocation;
313
+ }) => boolean);
294
314
  /**
295
315
  * A function that will be called to get the key for the scroll restoration cache.
296
316
  *
@@ -319,7 +339,42 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
319
339
  * @default false
320
340
  */
321
341
  disableGlobalCatchBoundary?: boolean;
342
+ serializationAdapters?: ReadonlyArray<AnySerializationAdapter>;
343
+ /**
344
+ * Configures how the router will rewrite the location between the actual href and the internal href of the router.
345
+ *
346
+ * @default undefined
347
+ * @description You can provide a custom rewrite pair (in/out) or use the utilities like `rewriteBasepath` as a convenience for common use cases, or even do both!
348
+ * This is useful for basepath rewriting, shifting data from the origin to the path (for things like )
349
+ */
350
+ rewrite?: LocationRewrite;
351
+ origin?: string;
322
352
  }
353
+ export type LocationRewrite = {
354
+ /**
355
+ * A function that will be called to rewrite the URL before it is interpreted by the router from the history instance.
356
+ * Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
357
+ *
358
+ * @default undefined
359
+ */
360
+ input?: LocationRewriteFunction;
361
+ /**
362
+ * A function that will be called to rewrite the URL before it is committed to the actual history instance from the router.
363
+ * Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
364
+ *
365
+ * @default undefined
366
+ */
367
+ output?: LocationRewriteFunction;
368
+ };
369
+ /**
370
+ * A function that will be called to rewrite the URL.
371
+ *
372
+ * @param url The URL to rewrite.
373
+ * @returns The rewritten URL (as a URL instance or full href string) or undefined if no rewrite is needed.
374
+ */
375
+ export type LocationRewriteFunction = ({ url, }: {
376
+ url: URL;
377
+ }) => undefined | string | URL;
323
378
  export interface RouterState<in out TRouteTree extends AnyRoute = AnyRoute, in out TRouteMatch = MakeRouteMatchUnion> {
324
379
  status: 'pending' | 'idle';
325
380
  loadedAt: number;
@@ -408,7 +463,7 @@ export type InvalidateFn<TRouter extends AnyRouter> = (opts?: {
408
463
  sync?: boolean;
409
464
  forcePending?: boolean;
410
465
  }) => Promise<void>;
411
- export type ParseLocationFn<TRouteTree extends AnyRoute> = (previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>, locationToParse?: HistoryLocation) => ParsedLocation<FullSearchSchema<TRouteTree>>;
466
+ export type ParseLocationFn<TRouteTree extends AnyRoute> = (locationToParse: HistoryLocation, previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>) => ParsedLocation<FullSearchSchema<TRouteTree>>;
412
467
  export type GetMatchRoutesFn = (pathname: string, routePathname: string | undefined) => {
413
468
  matchedRoutes: Array<AnyRoute>;
414
469
  routeParams: Record<string, string>;
@@ -486,6 +541,8 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
486
541
  __store: Store<RouterState<TRouteTree>>;
487
542
  options: PickAsRequired<RouterOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>;
488
543
  history: TRouterHistory;
544
+ rewrite?: LocationRewrite;
545
+ origin?: string;
489
546
  latestLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
490
547
  basepath: string;
491
548
  routeTree: TRouteTree;
@@ -502,7 +559,8 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
502
559
  isShell(): boolean;
503
560
  isPrerendering(): boolean;
504
561
  update: UpdateFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
505
- get state(): RouterState<TRouteTree, import('./Matches.js').RouteMatch<any, any, any, any, any, any, any>>;
562
+ get state(): RouterState<TRouteTree>;
563
+ updateLatestLocation: () => void;
506
564
  buildRouteTree: () => void;
507
565
  subscribe: SubscribeFn;
508
566
  emit: EmitFn;
@@ -527,41 +585,17 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
527
585
  startViewTransition: (fn: () => Promise<void>) => void;
528
586
  updateMatch: UpdateMatchFn;
529
587
  getMatch: GetMatchFn;
530
- private triggerOnReady;
531
- private resolvePreload;
532
- private handleRedirectAndNotFound;
533
- private shouldSkipLoader;
534
- private handleSerialError;
535
- private isBeforeLoadSsr;
536
- private setupPendingTimeout;
537
- private shouldExecuteBeforeLoad;
538
- private executeBeforeLoad;
539
- private handleBeforeLoad;
540
- private executeHead;
541
- private potentialPendingMinPromise;
542
- private getLoaderContext;
543
- private runLoader;
544
- private loadRouteMatch;
545
- loadMatches: (baseContext: {
546
- location: ParsedLocation;
547
- matches: Array<AnyRouteMatch>;
548
- preload?: boolean;
549
- onReady?: () => Promise<void>;
550
- updateMatch?: UpdateMatchFn;
551
- sync?: boolean;
552
- }) => Promise<Array<MakeRouteMatch>>;
553
588
  invalidate: InvalidateFn<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>>;
554
589
  resolveRedirect: (redirect: AnyRedirect) => AnyRedirect;
555
590
  clearCache: ClearCacheFn<this>;
556
591
  clearExpiredCache: () => void;
557
- loadRouteChunk: (route: AnyRoute) => Promise<void> | undefined;
592
+ loadRouteChunk: typeof loadRouteChunk;
558
593
  preloadRoute: PreloadRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
559
594
  matchRoute: MatchRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
560
595
  ssr?: {
561
596
  manifest: Manifest | undefined;
562
597
  };
563
598
  serverSsr?: ServerSsr;
564
- private _handleNotFound;
565
599
  hasNotFoundMatch: () => boolean;
566
600
  }
567
601
  export declare class SearchParamError extends Error {
@@ -570,7 +604,6 @@ export declare class PathParamError extends Error {
570
604
  }
571
605
  export declare function lazyFn<T extends Record<string, (...args: Array<any>) => any>, TKey extends keyof T = 'default'>(fn: () => Promise<T>, key?: TKey): (...args: Parameters<T[TKey]>) => Promise<Awaited<ReturnType<T[TKey]>>>;
572
606
  export declare function getInitialRouterState(location: ParsedLocation): RouterState<any>;
573
- export declare const componentTypes: readonly ["component", "errorComponent", "pendingComponent", "notFoundComponent"];
574
607
  interface RouteLike {
575
608
  id: string;
576
609
  isRoot?: boolean;
@@ -592,10 +625,9 @@ export declare function processRouteTree<TRouteLike extends RouteLike>({ routeTr
592
625
  routeTree: TRouteLike;
593
626
  initRoute?: (route: TRouteLike, index: number) => void;
594
627
  }): ProcessRouteTreeResult<TRouteLike>;
595
- export declare function getMatchedRoutes<TRouteLike extends RouteLike>({ pathname, routePathname, basepath, caseSensitive, routesByPath, routesById, flatRoutes, parseCache, }: {
628
+ export declare function getMatchedRoutes<TRouteLike extends RouteLike>({ pathname, routePathname, caseSensitive, routesByPath, routesById, flatRoutes, parseCache, }: {
596
629
  pathname: string;
597
630
  routePathname?: string;
598
- basepath: string;
599
631
  caseSensitive?: boolean;
600
632
  routesByPath: Record<string, TRouteLike>;
601
633
  routesById: Record<string, TRouteLike>;