@tanstack/react-router 1.43.6 → 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.
@@ -411,7 +411,9 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
411
411
  matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "", TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
412
412
  dehydrate: () => DehydratedRouter;
413
413
  hydrate: () => Promise<void>;
414
- injectedHtml: Array<string>;
414
+ injectedHtml: Array<() => string>;
415
+ injectHtml: (html: string) => void;
416
+ streamedKeys: Set<string>;
415
417
  getStreamedValue: <T>(key: string) => T | undefined;
416
418
  streamValue: (key: string, value: any) => void;
417
419
  handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError) => void;
@@ -411,7 +411,9 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
411
411
  matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "", TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
412
412
  dehydrate: () => DehydratedRouter;
413
413
  hydrate: () => Promise<void>;
414
- injectedHtml: Array<string>;
414
+ injectedHtml: Array<() => string>;
415
+ injectHtml: (html: string) => void;
416
+ streamedKeys: Set<string>;
415
417
  getStreamedValue: <T>(key: string) => T | undefined;
416
418
  streamValue: (key: string, value: any) => void;
417
419
  handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError) => void;
@@ -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.js";
5
6
  import { defaultStringifySearch, defaultParseSearch } from "./searchParams.js";
6
7
  import { createControlledPromise, replaceEqualDeep, pick, last, deepEqual, functionalUpdate } from "./utils.js";
@@ -1234,6 +1235,14 @@ class Router {
1234
1235
  this.manifest = ctx.router.manifest;
1235
1236
  };
1236
1237
  this.injectedHtml = [];
1238
+ this.injectHtml = (html) => {
1239
+ const cb = () => {
1240
+ this.injectedHtml = this.injectedHtml.filter((d) => d !== cb);
1241
+ return html;
1242
+ };
1243
+ this.injectedHtml.push(cb);
1244
+ };
1245
+ this.streamedKeys = /* @__PURE__ */ new Set();
1237
1246
  this.getStreamedValue = (key) => {
1238
1247
  var _a;
1239
1248
  if (this.isServer) {
@@ -1250,10 +1259,15 @@ class Router {
1250
1259
  };
1251
1260
  this.streamValue = (key, value) => {
1252
1261
  var _a;
1253
- const children = `window.__TSR__.streamedValues['${key}'] = { value: ${(_a = this.serializer) == null ? void 0 : _a.call(this, this.options.transformer.stringify(value))}}`;
1254
- this.injectedHtml.push(
1262
+ warning(
1263
+ !this.streamedKeys.has(key),
1264
+ "Key has already been streamed: " + key
1265
+ );
1266
+ this.streamedKeys.add(key);
1267
+ const children = `__TSR__.streamedValues['${key}'] = { value: ${(_a = this.serializer) == null ? void 0 : _a.call(this, this.options.transformer.stringify(value))}}`;
1268
+ this.injectHtml(
1255
1269
  `<script class='tsr-once'>${children}${process.env.NODE_ENV === "development" ? `; console.info(\`Injected From Server:
1256
- ${children}\`)` : ""}<\/script>`
1270
+ ${children}\`)` : ""}; __TSR__.cleanScripts()<\/script>`
1257
1271
  );
1258
1272
  };
1259
1273
  this.handleNotFound = (matches, err) => {