@tanstack/react-router 1.43.3 → 1.43.6

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/src/route.ts CHANGED
@@ -429,6 +429,28 @@ export interface AnyRoute
429
429
  any
430
430
  > {}
431
431
 
432
+ export type AnyRouteWithContext<TContext> = Route<
433
+ any,
434
+ any,
435
+ any,
436
+ any,
437
+ any,
438
+ any,
439
+ any,
440
+ any,
441
+ any,
442
+ any,
443
+ any,
444
+ any,
445
+ any,
446
+ any,
447
+ TContext,
448
+ any,
449
+ any,
450
+ any,
451
+ any
452
+ >
453
+
432
454
  export type ResolveAllParamsFromParent<
433
455
  TParentRoute extends AnyRoute,
434
456
  TParams,
package/src/router.ts CHANGED
@@ -36,6 +36,7 @@ import type {
36
36
  import type {
37
37
  AnyContext,
38
38
  AnyRoute,
39
+ AnyRouteWithContext,
39
40
  AnySearchSchema,
40
41
  ErrorRouteComponent,
41
42
  LoaderFnContext,
@@ -83,7 +84,13 @@ declare global {
83
84
  interface Window {
84
85
  __TSR__?: {
85
86
  matches: Array<any>
86
- streamedValues: Record<string, any>
87
+ streamedValues: Record<
88
+ string,
89
+ {
90
+ value: any
91
+ parsed: any
92
+ }
93
+ >
87
94
  cleanScripts: () => void
88
95
  dehydrated?: any
89
96
  }
@@ -96,6 +103,12 @@ export interface Register {
96
103
  }
97
104
 
98
105
  export type AnyRouter = Router<any, any, any, any>
106
+ export type AnyRouterWithContext<TContext> = Router<
107
+ AnyRouteWithContext<TContext>,
108
+ any,
109
+ any,
110
+ any
111
+ >
99
112
 
100
113
  export type RegisteredRouter = Register extends {
101
114
  router: infer TRouter extends AnyRouter
@@ -565,7 +578,6 @@ export class Router<
565
578
  ...options,
566
579
  stringifySearch: options.stringifySearch ?? defaultStringifySearch,
567
580
  parseSearch: options.parseSearch ?? defaultParseSearch,
568
- transformer: options.transformer ?? JSON,
569
581
  })
570
582
 
571
583
  if (typeof document !== 'undefined') {
@@ -2344,19 +2356,19 @@ export class Router<
2344
2356
  }
2345
2357
  }
2346
2358
 
2347
- hydrate = async (__do_not_use_server_ctx?: string) => {
2348
- let _ctx = __do_not_use_server_ctx
2359
+ hydrate = async () => {
2349
2360
  // Client hydrates from window
2361
+ let ctx: HydrationCtx | undefined
2362
+
2350
2363
  if (typeof document !== 'undefined') {
2351
- _ctx = window.__TSR__?.dehydrated
2364
+ ctx = this.options.transformer.parse(window.__TSR__?.dehydrated) as any
2352
2365
  }
2353
2366
 
2354
2367
  invariant(
2355
- _ctx,
2368
+ ctx,
2356
2369
  'Expected to find a dehydrated data on window.__TSR__.dehydrated... but we did not. Please file an issue!',
2357
2370
  )
2358
2371
 
2359
- const ctx = this.options.transformer.parse(_ctx) as HydrationCtx
2360
2372
  this.dehydratedData = ctx.payload as any
2361
2373
  this.options.hydrate?.(ctx.payload as any)
2362
2374
  const dehydratedState = ctx.router.state
@@ -2397,11 +2409,21 @@ export class Router<
2397
2409
  return undefined
2398
2410
  }
2399
2411
 
2400
- return window.__TSR__?.streamedValues[key]
2412
+ const streamedValue = window.__TSR__?.streamedValues[key]
2413
+
2414
+ if (!streamedValue) {
2415
+ return
2416
+ }
2417
+
2418
+ if (!streamedValue.parsed) {
2419
+ streamedValue.parsed = this.options.transformer.parse(streamedValue.value)
2420
+ }
2421
+
2422
+ return streamedValue.parsed
2401
2423
  }
2402
2424
 
2403
2425
  streamValue = (key: string, value: any) => {
2404
- const children = `window.__TSR__.streamedValues['${key}'] = ${this.serializer?.(value)}`
2426
+ const children = `window.__TSR__.streamedValues['${key}'] = { value: ${this.serializer?.(this.options.transformer.stringify(value))}}`
2405
2427
  this.injectedHtml.push(
2406
2428
  `<script class='tsr-once'>${children}${
2407
2429
  process.env.NODE_ENV === 'development'