@tanstack/react-router 1.43.1 → 1.43.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.
- package/dist/cjs/Match.cjs +2 -2
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/ScriptOnce.cjs +2 -1
- package/dist/cjs/ScriptOnce.cjs.map +1 -1
- package/dist/cjs/router.cjs +18 -14
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +5 -0
- package/dist/esm/Match.js +2 -2
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/ScriptOnce.js +2 -1
- package/dist/esm/ScriptOnce.js.map +1 -1
- package/dist/esm/router.d.ts +5 -0
- package/dist/esm/router.js +18 -14
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/Match.tsx +1 -1
- package/src/ScriptOnce.tsx +3 -1
- package/src/router.ts +26 -21
package/src/router.ts
CHANGED
|
@@ -25,16 +25,14 @@ import {
|
|
|
25
25
|
} from './path'
|
|
26
26
|
import { isRedirect, isResolvedRedirect } from './redirects'
|
|
27
27
|
import { isNotFound } from './not-found'
|
|
28
|
-
import type { Manifest } from './manifest'
|
|
29
28
|
import type * as React from 'react'
|
|
29
|
+
import type { Manifest } from './manifest'
|
|
30
30
|
import type {
|
|
31
31
|
HistoryLocation,
|
|
32
32
|
HistoryState,
|
|
33
33
|
RouterHistory,
|
|
34
34
|
} from '@tanstack/history'
|
|
35
35
|
|
|
36
|
-
//
|
|
37
|
-
|
|
38
36
|
import type {
|
|
39
37
|
AnyContext,
|
|
40
38
|
AnyRoute,
|
|
@@ -85,6 +83,7 @@ declare global {
|
|
|
85
83
|
interface Window {
|
|
86
84
|
__TSR__?: {
|
|
87
85
|
matches: Array<any>
|
|
86
|
+
streamedValues: Record<string, any>
|
|
88
87
|
cleanScripts: () => void
|
|
89
88
|
dehydrated?: any
|
|
90
89
|
}
|
|
@@ -521,6 +520,7 @@ export class Router<
|
|
|
521
520
|
match: AnyRouteMatch
|
|
522
521
|
},
|
|
523
522
|
) => any
|
|
523
|
+
serializer?: (data: any) => string
|
|
524
524
|
|
|
525
525
|
// Must build in constructor
|
|
526
526
|
__store!: Store<RouterState<TRouteTree>>
|
|
@@ -2364,7 +2364,7 @@ export class Router<
|
|
|
2364
2364
|
const matches = this.matchRoutes(
|
|
2365
2365
|
this.state.location.pathname,
|
|
2366
2366
|
this.state.location.search,
|
|
2367
|
-
).map((match
|
|
2367
|
+
).map((match) => {
|
|
2368
2368
|
const dehydratedMatch = dehydratedState.dehydratedMatches.find(
|
|
2369
2369
|
(d) => d.id === match.id,
|
|
2370
2370
|
)
|
|
@@ -2374,26 +2374,9 @@ export class Router<
|
|
|
2374
2374
|
`Could not find a client-side match for dehydrated match with id: ${match.id}!`,
|
|
2375
2375
|
)
|
|
2376
2376
|
|
|
2377
|
-
const route = this.looseRoutesById[match.routeId]!
|
|
2378
|
-
|
|
2379
|
-
const assets =
|
|
2380
|
-
dehydratedMatch.status === 'notFound' ||
|
|
2381
|
-
dehydratedMatch.status === 'redirected'
|
|
2382
|
-
? {}
|
|
2383
|
-
: {
|
|
2384
|
-
meta: route.options.meta?.({
|
|
2385
|
-
matches: allMatches,
|
|
2386
|
-
params: match.params,
|
|
2387
|
-
loaderData: dehydratedMatch.loaderData,
|
|
2388
|
-
}),
|
|
2389
|
-
links: route.options.links?.(),
|
|
2390
|
-
scripts: route.options.scripts?.(),
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
2377
|
return {
|
|
2394
2378
|
...match,
|
|
2395
2379
|
...dehydratedMatch,
|
|
2396
|
-
...assets,
|
|
2397
2380
|
}
|
|
2398
2381
|
})
|
|
2399
2382
|
|
|
@@ -2407,6 +2390,28 @@ export class Router<
|
|
|
2407
2390
|
this.manifest = ctx.router.manifest
|
|
2408
2391
|
}
|
|
2409
2392
|
|
|
2393
|
+
injectedHtml: Array<string> = []
|
|
2394
|
+
|
|
2395
|
+
getStreamedValue = <T>(key: string): T | undefined => {
|
|
2396
|
+
if (this.isServer) {
|
|
2397
|
+
return undefined
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
return window.__TSR__?.streamedValues[key]
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
streamValue = (key: string, value: any) => {
|
|
2404
|
+
const children = `window.__TSR__.streamedValues['${key}'] = ${this.serializer?.(value)}`
|
|
2405
|
+
this.injectedHtml.push(
|
|
2406
|
+
`<script class='tsr-once'>${children}${
|
|
2407
|
+
process.env.NODE_ENV === 'development'
|
|
2408
|
+
? `; console.info(\`Injected From Server:
|
|
2409
|
+
${children}\`)`
|
|
2410
|
+
: ''
|
|
2411
|
+
}</script>`,
|
|
2412
|
+
)
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2410
2415
|
handleNotFound = (matches: Array<AnyRouteMatch>, err: NotFoundError) => {
|
|
2411
2416
|
const matchesByRouteId = Object.fromEntries(
|
|
2412
2417
|
matches.map((match) => [match.routeId, match]),
|