@tanstack/react-router 1.43.4 → 1.43.10

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/manifest.ts CHANGED
@@ -2,6 +2,7 @@ export type Manifest = {
2
2
  routes: Record<
3
3
  string,
4
4
  {
5
+ filePath?: string
5
6
  preloads?: Array<string>
6
7
  assets?: Array<RouterManagedTag>
7
8
  }
package/src/router.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createBrowserHistory, createMemoryHistory } from '@tanstack/history'
2
2
  import { Store } from '@tanstack/react-store'
3
3
  import invariant from 'tiny-invariant'
4
+ import warning from 'tiny-warning'
4
5
  import { rootRouteId } from './root'
5
6
  import { defaultParseSearch, defaultStringifySearch } from './searchParams'
6
7
  import {
@@ -2402,7 +2403,16 @@ export class Router<
2402
2403
  this.manifest = ctx.router.manifest
2403
2404
  }
2404
2405
 
2405
- injectedHtml: Array<string> = []
2406
+ injectedHtml: Array<() => string> = []
2407
+ injectHtml: (html: string) => void = (html) => {
2408
+ const cb = () => {
2409
+ this.injectedHtml = this.injectedHtml.filter((d) => d !== cb)
2410
+ return html
2411
+ }
2412
+
2413
+ this.injectedHtml.push(cb)
2414
+ }
2415
+ streamedKeys: Set<string> = new Set()
2406
2416
 
2407
2417
  getStreamedValue = <T>(key: string): T | undefined => {
2408
2418
  if (this.isServer) {
@@ -2423,14 +2433,21 @@ export class Router<
2423
2433
  }
2424
2434
 
2425
2435
  streamValue = (key: string, value: any) => {
2426
- const children = `window.__TSR__.streamedValues['${key}'] = { value: ${this.serializer?.(this.options.transformer.stringify(value))}}`
2427
- this.injectedHtml.push(
2436
+ warning(
2437
+ !this.streamedKeys.has(key),
2438
+ 'Key has already been streamed: ' + key,
2439
+ )
2440
+
2441
+ this.streamedKeys.add(key)
2442
+ const children = `__TSR__.streamedValues['${key}'] = { value: ${this.serializer?.(this.options.transformer.stringify(value))}}`
2443
+
2444
+ this.injectHtml(
2428
2445
  `<script class='tsr-once'>${children}${
2429
2446
  process.env.NODE_ENV === 'development'
2430
2447
  ? `; console.info(\`Injected From Server:
2431
- ${children}\`)`
2448
+ ${children}\`)`
2432
2449
  : ''
2433
- }</script>`,
2450
+ }; __TSR__.cleanScripts()</script>`,
2434
2451
  )
2435
2452
  }
2436
2453