@tanstack/router-core 1.168.1 → 1.168.3

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 (68) hide show
  1. package/dist/cjs/index.cjs +5 -0
  2. package/dist/cjs/index.d.cts +3 -1
  3. package/dist/cjs/invariant.cjs +8 -0
  4. package/dist/cjs/invariant.cjs.map +1 -0
  5. package/dist/cjs/invariant.d.cts +1 -0
  6. package/dist/cjs/load-matches.cjs +5 -4
  7. package/dist/cjs/load-matches.cjs.map +1 -1
  8. package/dist/cjs/manifest.cjs +18 -0
  9. package/dist/cjs/manifest.cjs.map +1 -0
  10. package/dist/cjs/manifest.d.cts +12 -1
  11. package/dist/cjs/new-process-route-tree.cjs +5 -4
  12. package/dist/cjs/new-process-route-tree.cjs.map +1 -1
  13. package/dist/cjs/path.cjs +0 -1
  14. package/dist/cjs/path.cjs.map +1 -1
  15. package/dist/cjs/route.cjs +5 -4
  16. package/dist/cjs/route.cjs.map +1 -1
  17. package/dist/cjs/router.cjs +0 -1
  18. package/dist/cjs/router.cjs.map +1 -1
  19. package/dist/cjs/scroll-restoration.cjs +0 -1
  20. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  21. package/dist/cjs/ssr/createRequestHandler.cjs +0 -1
  22. package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
  23. package/dist/cjs/ssr/headers.cjs +0 -1
  24. package/dist/cjs/ssr/headers.cjs.map +1 -1
  25. package/dist/cjs/ssr/serializer/RawStream.cjs +0 -1
  26. package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -1
  27. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs +0 -1
  28. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -1
  29. package/dist/cjs/ssr/serializer/seroval-plugins.cjs +0 -1
  30. package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -1
  31. package/dist/cjs/ssr/serializer/transformer.cjs +0 -1
  32. package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -1
  33. package/dist/cjs/ssr/ssr-client.cjs +13 -6
  34. package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
  35. package/dist/cjs/ssr/ssr-server.cjs +5 -4
  36. package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
  37. package/dist/cjs/ssr/transformStreamWithRouter.cjs +0 -1
  38. package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
  39. package/dist/cjs/utils.cjs +0 -1
  40. package/dist/cjs/utils.cjs.map +1 -1
  41. package/dist/esm/index.d.ts +3 -1
  42. package/dist/esm/index.js +3 -1
  43. package/dist/esm/invariant.d.ts +1 -0
  44. package/dist/esm/invariant.js +8 -0
  45. package/dist/esm/invariant.js.map +1 -0
  46. package/dist/esm/load-matches.js +5 -2
  47. package/dist/esm/load-matches.js.map +1 -1
  48. package/dist/esm/manifest.d.ts +12 -1
  49. package/dist/esm/manifest.js +17 -0
  50. package/dist/esm/manifest.js.map +1 -0
  51. package/dist/esm/new-process-route-tree.js +5 -2
  52. package/dist/esm/new-process-route-tree.js.map +1 -1
  53. package/dist/esm/route.js +5 -2
  54. package/dist/esm/route.js.map +1 -1
  55. package/dist/esm/ssr/ssr-client.js +13 -4
  56. package/dist/esm/ssr/ssr-client.js.map +1 -1
  57. package/dist/esm/ssr/ssr-server.js +5 -2
  58. package/dist/esm/ssr/ssr-server.js.map +1 -1
  59. package/package.json +1 -3
  60. package/src/index.ts +9 -1
  61. package/src/invariant.ts +3 -0
  62. package/src/load-matches.ts +10 -5
  63. package/src/manifest.ts +37 -1
  64. package/src/new-process-route-tree.ts +10 -5
  65. package/src/route.ts +8 -5
  66. package/src/ssr/ssr-client.ts +28 -13
  67. package/src/ssr/ssr-server.ts +8 -2
  68. package/dist/cjs/_virtual/_rolldown/runtime.cjs +0 -23
package/src/manifest.ts CHANGED
@@ -1,9 +1,45 @@
1
+ export type AssetCrossOrigin = 'anonymous' | 'use-credentials'
2
+
3
+ export type AssetCrossOriginConfig =
4
+ | AssetCrossOrigin
5
+ | Partial<Record<'modulepreload' | 'stylesheet', AssetCrossOrigin>>
6
+
7
+ export type ManifestAssetLink =
8
+ | string
9
+ | {
10
+ href: string
11
+ crossOrigin?: AssetCrossOrigin
12
+ }
13
+
14
+ export function getAssetCrossOrigin(
15
+ assetCrossOrigin: AssetCrossOriginConfig | undefined,
16
+ kind: 'modulepreload' | 'stylesheet',
17
+ ): AssetCrossOrigin | undefined {
18
+ if (!assetCrossOrigin) {
19
+ return undefined
20
+ }
21
+
22
+ if (typeof assetCrossOrigin === 'string') {
23
+ return assetCrossOrigin
24
+ }
25
+
26
+ return assetCrossOrigin[kind]
27
+ }
28
+
29
+ export function resolveManifestAssetLink(link: ManifestAssetLink) {
30
+ if (typeof link === 'string') {
31
+ return { href: link, crossOrigin: undefined }
32
+ }
33
+
34
+ return link
35
+ }
36
+
1
37
  export type Manifest = {
2
38
  routes: Record<
3
39
  string,
4
40
  {
5
41
  filePath?: string
6
- preloads?: Array<string>
42
+ preloads?: Array<ManifestAssetLink>
7
43
  assets?: Array<RouterManagedTag>
8
44
  }
9
45
  >
@@ -1,4 +1,4 @@
1
- import invariant from 'tiny-invariant'
1
+ import { invariant } from './invariant'
2
2
  import { createLRUCache } from './lru-cache'
3
3
  import { last } from './utils'
4
4
  import type { LRUCache } from './lru-cache'
@@ -811,10 +811,15 @@ export function processRouteTree<
811
811
  parseSegments(caseSensitive, data, routeTree, 1, segmentTree, 0, (route) => {
812
812
  initRoute?.(route, index)
813
813
 
814
- invariant(
815
- !(route.id in routesById),
816
- `Duplicate routes found with id: ${String(route.id)}`,
817
- )
814
+ if (route.id in routesById) {
815
+ if (process.env.NODE_ENV !== 'production') {
816
+ throw new Error(
817
+ `Invariant failed: Duplicate routes found with id: ${String(route.id)}`,
818
+ )
819
+ }
820
+
821
+ invariant()
822
+ }
818
823
 
819
824
  routesById[route.id] = route
820
825
 
package/src/route.ts CHANGED
@@ -1,4 +1,4 @@
1
- import invariant from 'tiny-invariant'
1
+ import { invariant } from './invariant'
2
2
  import { joinPaths, trimPathLeft, trimPathRight } from './path'
3
3
  import { notFound } from './not-found'
4
4
  import { redirect } from './redirect'
@@ -1808,10 +1808,13 @@ export class BaseRoute<
1808
1808
  if (isRoot) {
1809
1809
  this._path = rootRouteId as TPath
1810
1810
  } else if (!this.parentRoute) {
1811
- invariant(
1812
- false,
1813
- `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,
1814
- )
1811
+ if (process.env.NODE_ENV !== 'production') {
1812
+ throw new Error(
1813
+ `Invariant failed: Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,
1814
+ )
1815
+ }
1816
+
1817
+ invariant()
1815
1818
  }
1816
1819
 
1817
1820
  let path: undefined | string = isRoot ? rootRouteId : options?.path
@@ -1,4 +1,4 @@
1
- import invariant from 'tiny-invariant'
1
+ import { invariant } from '../invariant'
2
2
  import { isNotFound } from '../not-found'
3
3
  import { createControlledPromise } from '../utils'
4
4
  import { hydrateSsrMatchId } from './ssr-match-id'
@@ -38,10 +38,15 @@ function hydrateMatch(
38
38
  }
39
39
 
40
40
  export async function hydrate(router: AnyRouter): Promise<any> {
41
- invariant(
42
- window.$_TSR,
43
- 'Expected to find bootstrap data on window.$_TSR, but we did not. Please file an issue!',
44
- )
41
+ if (!window.$_TSR) {
42
+ if (process.env.NODE_ENV !== 'production') {
43
+ throw new Error(
44
+ 'Invariant failed: Expected to find bootstrap data on window.$_TSR, but we did not. Please file an issue!',
45
+ )
46
+ }
47
+
48
+ invariant()
49
+ }
45
50
 
46
51
  const serializationAdapters = router.options.serializationAdapters as
47
52
  | Array<AnySerializationAdapter>
@@ -57,10 +62,15 @@ export async function hydrate(router: AnyRouter): Promise<any> {
57
62
  }
58
63
  window.$_TSR.initialized = true
59
64
 
60
- invariant(
61
- window.$_TSR.router,
62
- 'Expected to find a dehydrated data on window.$_TSR.router, but we did not. Please file an issue!',
63
- )
65
+ if (!window.$_TSR.router) {
66
+ if (process.env.NODE_ENV !== 'production') {
67
+ throw new Error(
68
+ 'Invariant failed: Expected to find a dehydrated data on window.$_TSR.router, but we did not. Please file an issue!',
69
+ )
70
+ }
71
+
72
+ invariant()
73
+ }
64
74
 
65
75
  const dehydratedRouter = window.$_TSR.router
66
76
  dehydratedRouter.matches.forEach((dehydratedMatch) => {
@@ -258,10 +268,15 @@ export async function hydrate(router: AnyRouter): Promise<any> {
258
268
  // this will prevent that other pending components are rendered but hydration is not blocked
259
269
  if (isSpaMode) {
260
270
  const match = matches[1]
261
- invariant(
262
- match,
263
- 'Expected to find a match below the root match in SPA mode.',
264
- )
271
+ if (!match) {
272
+ if (process.env.NODE_ENV !== 'production') {
273
+ throw new Error(
274
+ 'Invariant failed: Expected to find a match below the root match in SPA mode.',
275
+ )
276
+ }
277
+
278
+ invariant()
279
+ }
265
280
  setMatchForcePending(match)
266
281
 
267
282
  match._displayPending = true
@@ -1,5 +1,5 @@
1
1
  import { crossSerializeStream, getCrossReferenceHeader } from 'seroval'
2
- import invariant from 'tiny-invariant'
2
+ import { invariant } from '../invariant'
3
3
  import { decodePath } from '../utils'
4
4
  import { createLRUCache } from '../lru-cache'
5
5
  import minifiedTsrBootStrapScript from './tsrScript?script-string'
@@ -201,7 +201,13 @@ export function attachRouterServerSsrUtils({
201
201
  router.serverSsr!.injectHtml(html)
202
202
  },
203
203
  dehydrate: async () => {
204
- invariant(!_dehydrated, 'router is already dehydrated!')
204
+ if (_dehydrated) {
205
+ if (process.env.NODE_ENV !== 'production') {
206
+ throw new Error('Invariant failed: router is already dehydrated!')
207
+ }
208
+
209
+ invariant()
210
+ }
205
211
  let matchesToDehydrate = router.stores.activeMatchesSnapshot.state
206
212
  if (router.isShell()) {
207
213
  // In SPA mode we only want to dehydrate the root match
@@ -1,23 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
- //#endregion
23
- exports.__toESM = __toESM;