react-router 7.9.4 → 7.9.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/development/browser-BbBXFHbO.d.ts +310 -0
  3. package/dist/development/browser-C07r42Tt.d.mts +310 -0
  4. package/dist/development/{chunk-OIYGIGL5.mjs → chunk-4WY6JWTD.mjs} +458 -43
  5. package/dist/development/{chunk-DI2QHYMJ.js → chunk-AMVS5XVJ.js} +1314 -138
  6. package/dist/development/{chunk-WY5IRSCW.mjs → chunk-G3INQAYP.mjs} +197 -857
  7. package/dist/development/chunk-O4JVZSOY.js +1310 -0
  8. package/dist/development/chunk-PZWDWJAY.js +188 -0
  9. package/dist/development/dom-export.d.mts +103 -6
  10. package/dist/development/dom-export.d.ts +103 -4
  11. package/dist/development/dom-export.js +708 -20
  12. package/dist/development/dom-export.mjs +692 -11
  13. package/dist/{production/index-react-server-client-BbRcBjrA.d.ts → development/index-react-server-client-Da3kmxNd.d.ts} +195 -135
  14. package/dist/{production/index-react-server-client-BIz4AUNd.d.mts → development/index-react-server-client-rcoGPJhU.d.mts} +137 -78
  15. package/dist/development/index-react-server-client.d.mts +2 -3
  16. package/dist/development/index-react-server-client.d.ts +2 -2
  17. package/dist/development/index-react-server-client.js +4 -4
  18. package/dist/development/index-react-server-client.mjs +2 -2
  19. package/dist/development/index-react-server.d.mts +107 -3
  20. package/dist/development/index-react-server.d.ts +107 -3
  21. package/dist/development/index-react-server.js +259 -13
  22. package/dist/development/index-react-server.mjs +259 -13
  23. package/dist/development/index.d.mts +14 -320
  24. package/dist/development/index.d.ts +14 -362
  25. package/dist/development/index.js +146 -962
  26. package/dist/development/index.mjs +3 -9
  27. package/dist/development/{routeModules-D5iJ6JYT.d.ts → instrumentation-Unc20tLk.d.ts} +178 -25
  28. package/dist/development/lib/types/internal.d.mts +2 -3
  29. package/dist/development/lib/types/internal.d.ts +2 -2
  30. package/dist/development/lib/types/internal.js +1 -1
  31. package/dist/development/lib/types/internal.mjs +1 -1
  32. package/dist/{production/register-C34pU-in.d.ts → development/register-BpU9rFBJ.d.ts} +1 -1
  33. package/dist/development/{register-CI4bTprK.d.mts → register-QkB3HGjm.d.mts} +1 -1
  34. package/dist/{production/context-DSyS5mLj.d.mts → development/router-CAvh_Drx.d.mts} +1877 -1254
  35. package/dist/production/browser-BbBXFHbO.d.ts +310 -0
  36. package/dist/production/browser-C07r42Tt.d.mts +310 -0
  37. package/dist/production/{chunk-4E5LHRQP.js → chunk-EAIF67OW.js} +1314 -138
  38. package/dist/production/{chunk-FR6HSPLK.mjs → chunk-FDUMZGKM.mjs} +197 -857
  39. package/dist/production/{chunk-3TADTUL4.mjs → chunk-FUSXQSWG.mjs} +458 -43
  40. package/dist/production/chunk-G5A35OQU.js +188 -0
  41. package/dist/production/chunk-QN64DHI4.js +1310 -0
  42. package/dist/production/dom-export.d.mts +103 -6
  43. package/dist/production/dom-export.d.ts +103 -4
  44. package/dist/production/dom-export.js +708 -20
  45. package/dist/production/dom-export.mjs +692 -11
  46. package/dist/{development/index-react-server-client-BIz4AUNd.d.mts → production/index-react-server-client-Da3kmxNd.d.ts} +137 -78
  47. package/dist/{development/index-react-server-client-BbRcBjrA.d.ts → production/index-react-server-client-rcoGPJhU.d.mts} +195 -135
  48. package/dist/production/index-react-server-client.d.mts +2 -3
  49. package/dist/production/index-react-server-client.d.ts +2 -2
  50. package/dist/production/index-react-server-client.js +4 -4
  51. package/dist/production/index-react-server-client.mjs +2 -2
  52. package/dist/production/index-react-server.d.mts +107 -3
  53. package/dist/production/index-react-server.d.ts +107 -3
  54. package/dist/production/index-react-server.js +259 -13
  55. package/dist/production/index-react-server.mjs +259 -13
  56. package/dist/production/index.d.mts +14 -320
  57. package/dist/production/index.d.ts +14 -362
  58. package/dist/production/index.js +146 -962
  59. package/dist/production/index.mjs +3 -9
  60. package/dist/production/{routeModules-D5iJ6JYT.d.ts → instrumentation-Unc20tLk.d.ts} +178 -25
  61. package/dist/production/lib/types/internal.d.mts +2 -3
  62. package/dist/production/lib/types/internal.d.ts +2 -2
  63. package/dist/production/lib/types/internal.js +1 -1
  64. package/dist/production/lib/types/internal.mjs +1 -1
  65. package/dist/{development/register-C34pU-in.d.ts → production/register-BpU9rFBJ.d.ts} +1 -1
  66. package/dist/production/{register-CI4bTprK.d.mts → register-QkB3HGjm.d.mts} +1 -1
  67. package/dist/{development/context-DSyS5mLj.d.mts → production/router-CAvh_Drx.d.mts} +1877 -1254
  68. package/package.json +1 -1
  69. package/dist/development/browser-z32v5KVN.d.mts +0 -46
  70. package/dist/development/chunk-72XNTZCV.js +0 -2089
  71. package/dist/development/route-data-DZQOUSqV.d.mts +0 -473
  72. package/dist/production/browser-z32v5KVN.d.mts +0 -46
  73. package/dist/production/chunk-WNLQ53P5.js +0 -2089
  74. package/dist/production/route-data-DZQOUSqV.d.mts +0 -473
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.9.4
2
+ * react-router v7.9.6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,26 +10,40 @@
10
10
  */
11
11
  "use client";
12
12
  import {
13
+ RSCRouterGlobalErrorBoundary,
13
14
  deserializeErrors,
14
- getHydrationData
15
- } from "./chunk-WY5IRSCW.mjs";
15
+ getHydrationData,
16
+ populateRSCRouteModules
17
+ } from "./chunk-G3INQAYP.mjs";
16
18
  import {
17
19
  CRITICAL_CSS_DATA_ATTRIBUTE,
20
+ ErrorResponseImpl,
18
21
  FrameworkContext,
22
+ RSCRouterContext,
19
23
  RemixErrorBoundary,
20
24
  RouterProvider,
25
+ UNSTABLE_TransitionEnabledRouterProvider,
21
26
  createBrowserHistory,
22
27
  createClientRoutes,
23
28
  createClientRoutesWithHMRRevalidationOptOut,
29
+ createContext,
30
+ createRequestInit,
24
31
  createRouter,
25
32
  decodeViaTurboStream,
26
33
  getPatchRoutesOnNavigationFunction,
34
+ getSingleFetchDataStrategyImpl,
27
35
  getTurboStreamSingleFetchDataStrategy,
28
36
  hydrationRouteProperties,
29
37
  invariant,
38
+ isMutationMethod,
30
39
  mapRouteProperties,
40
+ noActionDefinedError,
41
+ setIsHydrated,
42
+ shouldHydrateRouteLoader,
43
+ singleFetchUrl,
44
+ stripIndexParam,
31
45
  useFogOFWarDiscovery
32
- } from "./chunk-OIYGIGL5.mjs";
46
+ } from "./chunk-4WY6JWTD.mjs";
33
47
 
34
48
  // lib/dom-export/dom-router-provider.tsx
35
49
  import * as React from "react";
@@ -67,7 +81,8 @@ function initSsrInfo() {
67
81
  }
68
82
  }
69
83
  function createHydratedRouter({
70
- getContext
84
+ getContext,
85
+ unstable_instrumentations
71
86
  }) {
72
87
  initSsrInfo();
73
88
  if (!ssrInfo) {
@@ -134,6 +149,7 @@ function createHydratedRouter({
134
149
  getContext,
135
150
  hydrationData,
136
151
  hydrationRouteProperties,
152
+ unstable_instrumentations,
137
153
  mapRouteProperties,
138
154
  future: {
139
155
  middleware: ssrInfo.context.future.v8_middleware
@@ -167,7 +183,8 @@ function createHydratedRouter({
167
183
  function HydratedRouter(props) {
168
184
  if (!router) {
169
185
  router = createHydratedRouter({
170
- getContext: props.getContext
186
+ getContext: props.getContext,
187
+ unstable_instrumentations: props.unstable_instrumentations
171
188
  });
172
189
  }
173
190
  let [criticalCss, setCriticalCss] = React2.useState(
@@ -183,7 +200,7 @@ function HydratedRouter(props) {
183
200
  document.querySelectorAll(`[${CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
184
201
  }
185
202
  }, [criticalCss]);
186
- let [location, setLocation] = React2.useState(router.state.location);
203
+ let [location2, setLocation] = React2.useState(router.state.location);
187
204
  React2.useLayoutEffect(() => {
188
205
  if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
189
206
  ssrInfo.routerInitialized = true;
@@ -193,12 +210,12 @@ function HydratedRouter(props) {
193
210
  React2.useLayoutEffect(() => {
194
211
  if (ssrInfo && ssrInfo.router) {
195
212
  return ssrInfo.router.subscribe((newState) => {
196
- if (newState.location !== location) {
213
+ if (newState.location !== location2) {
197
214
  setLocation(newState.location);
198
215
  }
199
216
  });
200
217
  }
201
- }, [location]);
218
+ }, [location2]);
202
219
  invariant(ssrInfo, "ssrInfo unavailable for HydratedRouter");
203
220
  useFogOFWarDiscovery(
204
221
  router,
@@ -224,7 +241,7 @@ function HydratedRouter(props) {
224
241
  routeDiscovery: ssrInfo.context.routeDiscovery
225
242
  }
226
243
  },
227
- /* @__PURE__ */ React2.createElement(RemixErrorBoundary, { location }, /* @__PURE__ */ React2.createElement(
244
+ /* @__PURE__ */ React2.createElement(RemixErrorBoundary, { location: location2 }, /* @__PURE__ */ React2.createElement(
228
245
  RouterProvider2,
229
246
  {
230
247
  router,
@@ -234,7 +251,671 @@ function HydratedRouter(props) {
234
251
  ), /* @__PURE__ */ React2.createElement(React2.Fragment, null))
235
252
  );
236
253
  }
254
+
255
+ // lib/rsc/browser.tsx
256
+ import * as React3 from "react";
257
+ import * as ReactDOM2 from "react-dom";
258
+ function createCallServer({
259
+ createFromReadableStream,
260
+ createTemporaryReferenceSet,
261
+ encodeReply,
262
+ fetch: fetchImplementation = fetch
263
+ }) {
264
+ const globalVar = window;
265
+ let landedActionId = 0;
266
+ return async (id, args) => {
267
+ let actionId = globalVar.__routerActionID = (globalVar.__routerActionID ?? (globalVar.__routerActionID = 0)) + 1;
268
+ const temporaryReferences = createTemporaryReferenceSet();
269
+ const payloadPromise = fetchImplementation(
270
+ new Request(location.href, {
271
+ body: await encodeReply(args, { temporaryReferences }),
272
+ method: "POST",
273
+ headers: {
274
+ Accept: "text/x-component",
275
+ "rsc-action-id": id
276
+ }
277
+ })
278
+ ).then((response) => {
279
+ if (!response.body) {
280
+ throw new Error("No response body");
281
+ }
282
+ return createFromReadableStream(response.body, {
283
+ temporaryReferences
284
+ });
285
+ });
286
+ globalVar.__reactRouterDataRouter.__setPendingRerender(
287
+ Promise.resolve(payloadPromise).then(async (payload) => {
288
+ if (payload.type === "redirect") {
289
+ if (payload.reload || isExternalLocation(payload.location)) {
290
+ window.location.href = payload.location;
291
+ return () => {
292
+ };
293
+ }
294
+ return () => {
295
+ globalVar.__reactRouterDataRouter.navigate(payload.location, {
296
+ replace: payload.replace
297
+ });
298
+ };
299
+ }
300
+ if (payload.type !== "action") {
301
+ throw new Error("Unexpected payload type");
302
+ }
303
+ const rerender = await payload.rerender;
304
+ if (rerender && landedActionId < actionId && globalVar.__routerActionID <= actionId) {
305
+ if (rerender.type === "redirect") {
306
+ if (rerender.reload || isExternalLocation(rerender.location)) {
307
+ window.location.href = rerender.location;
308
+ return;
309
+ }
310
+ return () => {
311
+ globalVar.__reactRouterDataRouter.navigate(rerender.location, {
312
+ replace: rerender.replace
313
+ });
314
+ };
315
+ }
316
+ return () => {
317
+ let lastMatch;
318
+ for (const match of rerender.matches) {
319
+ globalVar.__reactRouterDataRouter.patchRoutes(
320
+ lastMatch?.id ?? null,
321
+ [createRouteFromServerManifest(match)],
322
+ true
323
+ );
324
+ lastMatch = match;
325
+ }
326
+ window.__reactRouterDataRouter._internalSetStateDoNotUseOrYouWillBreakYourApp(
327
+ {
328
+ loaderData: Object.assign(
329
+ {},
330
+ globalVar.__reactRouterDataRouter.state.loaderData,
331
+ rerender.loaderData
332
+ ),
333
+ errors: rerender.errors ? Object.assign(
334
+ {},
335
+ globalVar.__reactRouterDataRouter.state.errors,
336
+ rerender.errors
337
+ ) : null
338
+ }
339
+ );
340
+ };
341
+ }
342
+ return () => {
343
+ };
344
+ }).catch(() => {
345
+ })
346
+ );
347
+ return payloadPromise.then((payload) => {
348
+ if (payload.type !== "action" && payload.type !== "redirect") {
349
+ throw new Error("Unexpected payload type");
350
+ }
351
+ return payload.actionResult;
352
+ });
353
+ };
354
+ }
355
+ function createRouterFromPayload({
356
+ fetchImplementation,
357
+ createFromReadableStream,
358
+ getContext,
359
+ payload
360
+ }) {
361
+ const globalVar = window;
362
+ if (globalVar.__reactRouterDataRouter && globalVar.__reactRouterRouteModules)
363
+ return {
364
+ router: globalVar.__reactRouterDataRouter,
365
+ routeModules: globalVar.__reactRouterRouteModules
366
+ };
367
+ if (payload.type !== "render") throw new Error("Invalid payload type");
368
+ globalVar.__reactRouterRouteModules = globalVar.__reactRouterRouteModules ?? {};
369
+ populateRSCRouteModules(globalVar.__reactRouterRouteModules, payload.matches);
370
+ let patches = /* @__PURE__ */ new Map();
371
+ payload.patches?.forEach((patch) => {
372
+ invariant(patch.parentId, "Invalid patch parentId");
373
+ if (!patches.has(patch.parentId)) {
374
+ patches.set(patch.parentId, []);
375
+ }
376
+ patches.get(patch.parentId)?.push(patch);
377
+ });
378
+ let routes = payload.matches.reduceRight((previous, match) => {
379
+ const route = createRouteFromServerManifest(
380
+ match,
381
+ payload
382
+ );
383
+ if (previous.length > 0) {
384
+ route.children = previous;
385
+ let childrenToPatch = patches.get(match.id);
386
+ if (childrenToPatch) {
387
+ route.children.push(
388
+ ...childrenToPatch.map((r) => createRouteFromServerManifest(r))
389
+ );
390
+ }
391
+ }
392
+ return [route];
393
+ }, []);
394
+ globalVar.__reactRouterDataRouter = createRouter({
395
+ routes,
396
+ getContext,
397
+ basename: payload.basename,
398
+ history: createBrowserHistory(),
399
+ hydrationData: getHydrationData({
400
+ state: {
401
+ loaderData: payload.loaderData,
402
+ actionData: payload.actionData,
403
+ errors: payload.errors
404
+ },
405
+ routes,
406
+ getRouteInfo: (routeId) => {
407
+ let match = payload.matches.find((m) => m.id === routeId);
408
+ invariant(match, "Route not found in payload");
409
+ return {
410
+ clientLoader: match.clientLoader,
411
+ hasLoader: match.hasLoader,
412
+ hasHydrateFallback: match.hydrateFallbackElement != null
413
+ };
414
+ },
415
+ location: payload.location,
416
+ basename: payload.basename,
417
+ isSpaMode: false
418
+ }),
419
+ async patchRoutesOnNavigation({ path, signal }) {
420
+ if (discoveredPaths.has(path)) {
421
+ return;
422
+ }
423
+ await fetchAndApplyManifestPatches(
424
+ [path],
425
+ createFromReadableStream,
426
+ fetchImplementation,
427
+ signal
428
+ );
429
+ },
430
+ // FIXME: Pass `build.ssr` into this function
431
+ dataStrategy: getRSCSingleFetchDataStrategy(
432
+ () => globalVar.__reactRouterDataRouter,
433
+ true,
434
+ payload.basename,
435
+ createFromReadableStream,
436
+ fetchImplementation
437
+ )
438
+ });
439
+ if (globalVar.__reactRouterDataRouter.state.initialized) {
440
+ globalVar.__routerInitialized = true;
441
+ globalVar.__reactRouterDataRouter.initialize();
442
+ } else {
443
+ globalVar.__routerInitialized = false;
444
+ }
445
+ let lastLoaderData = void 0;
446
+ globalVar.__reactRouterDataRouter.subscribe(({ loaderData, actionData }) => {
447
+ if (lastLoaderData !== loaderData) {
448
+ globalVar.__routerActionID = (globalVar.__routerActionID ?? (globalVar.__routerActionID = 0)) + 1;
449
+ }
450
+ });
451
+ globalVar.__reactRouterDataRouter._updateRoutesForHMR = (routeUpdateByRouteId) => {
452
+ const oldRoutes = window.__reactRouterDataRouter.routes;
453
+ const newRoutes = [];
454
+ function walkRoutes(routes2, parentId) {
455
+ return routes2.map((route) => {
456
+ const routeUpdate = routeUpdateByRouteId.get(route.id);
457
+ if (routeUpdate) {
458
+ const {
459
+ routeModule,
460
+ hasAction,
461
+ hasComponent,
462
+ hasErrorBoundary,
463
+ hasLoader
464
+ } = routeUpdate;
465
+ const newRoute = createRouteFromServerManifest({
466
+ clientAction: routeModule.clientAction,
467
+ clientLoader: routeModule.clientLoader,
468
+ element: route.element,
469
+ errorElement: route.errorElement,
470
+ handle: route.handle,
471
+ hasAction,
472
+ hasComponent,
473
+ hasErrorBoundary,
474
+ hasLoader,
475
+ hydrateFallbackElement: route.hydrateFallbackElement,
476
+ id: route.id,
477
+ index: route.index,
478
+ links: routeModule.links,
479
+ meta: routeModule.meta,
480
+ parentId,
481
+ path: route.path,
482
+ shouldRevalidate: routeModule.shouldRevalidate
483
+ });
484
+ if (route.children) {
485
+ newRoute.children = walkRoutes(route.children, route.id);
486
+ }
487
+ return newRoute;
488
+ }
489
+ const updatedRoute = { ...route };
490
+ if (route.children) {
491
+ updatedRoute.children = walkRoutes(route.children, route.id);
492
+ }
493
+ return updatedRoute;
494
+ });
495
+ }
496
+ newRoutes.push(
497
+ ...walkRoutes(oldRoutes, void 0)
498
+ );
499
+ window.__reactRouterDataRouter._internalSetRoutes(newRoutes);
500
+ };
501
+ return {
502
+ router: globalVar.__reactRouterDataRouter,
503
+ routeModules: globalVar.__reactRouterRouteModules
504
+ };
505
+ }
506
+ var renderedRoutesContext = createContext();
507
+ function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReadableStream, fetchImplementation) {
508
+ let dataStrategy = getSingleFetchDataStrategyImpl(
509
+ getRouter,
510
+ (match) => {
511
+ let M = match;
512
+ return {
513
+ hasLoader: M.route.hasLoader,
514
+ hasClientLoader: M.route.hasClientLoader,
515
+ hasComponent: M.route.hasComponent,
516
+ hasAction: M.route.hasAction,
517
+ hasClientAction: M.route.hasClientAction,
518
+ hasShouldRevalidate: M.route.hasShouldRevalidate
519
+ };
520
+ },
521
+ // pass map into fetchAndDecode so it can add payloads
522
+ getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation),
523
+ ssr,
524
+ basename,
525
+ // If the route has a component but we don't have an element, we need to hit
526
+ // the server loader flow regardless of whether the client loader calls
527
+ // `serverLoader` or not, otherwise we'll have nothing to render.
528
+ (match) => {
529
+ let M = match;
530
+ return M.route.hasComponent && !M.route.element;
531
+ }
532
+ );
533
+ return async (args) => args.runClientMiddleware(async () => {
534
+ let context = args.context;
535
+ context.set(renderedRoutesContext, []);
536
+ let results = await dataStrategy(args);
537
+ const renderedRoutesById = /* @__PURE__ */ new Map();
538
+ for (const route of context.get(renderedRoutesContext)) {
539
+ if (!renderedRoutesById.has(route.id)) {
540
+ renderedRoutesById.set(route.id, []);
541
+ }
542
+ renderedRoutesById.get(route.id).push(route);
543
+ }
544
+ for (const match of args.matches) {
545
+ const renderedRoutes = renderedRoutesById.get(match.route.id);
546
+ if (renderedRoutes) {
547
+ for (const rendered of renderedRoutes) {
548
+ window.__reactRouterDataRouter.patchRoutes(
549
+ rendered.parentId ?? null,
550
+ [createRouteFromServerManifest(rendered)],
551
+ true
552
+ );
553
+ }
554
+ }
555
+ }
556
+ return results;
557
+ });
558
+ }
559
+ function getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation) {
560
+ return async (args, basename, targetRoutes) => {
561
+ let { request, context } = args;
562
+ let url = singleFetchUrl(request.url, basename, "rsc");
563
+ if (request.method === "GET") {
564
+ url = stripIndexParam(url);
565
+ if (targetRoutes) {
566
+ url.searchParams.set("_routes", targetRoutes.join(","));
567
+ }
568
+ }
569
+ let res = await fetchImplementation(
570
+ new Request(url, await createRequestInit(request))
571
+ );
572
+ if (res.status >= 400 && !res.headers.has("X-Remix-Response")) {
573
+ throw new ErrorResponseImpl(res.status, res.statusText, await res.text());
574
+ }
575
+ invariant(res.body, "No response body to decode");
576
+ try {
577
+ const payload = await createFromReadableStream(res.body, {
578
+ temporaryReferences: void 0
579
+ });
580
+ if (payload.type === "redirect") {
581
+ return {
582
+ status: res.status,
583
+ data: {
584
+ redirect: {
585
+ redirect: payload.location,
586
+ reload: payload.reload,
587
+ replace: payload.replace,
588
+ revalidate: false,
589
+ status: payload.status
590
+ }
591
+ }
592
+ };
593
+ }
594
+ if (payload.type !== "render") {
595
+ throw new Error("Unexpected payload type");
596
+ }
597
+ context.get(renderedRoutesContext).push(...payload.matches);
598
+ let results = { routes: {} };
599
+ const dataKey = isMutationMethod(request.method) ? "actionData" : "loaderData";
600
+ for (let [routeId, data] of Object.entries(payload[dataKey] || {})) {
601
+ results.routes[routeId] = { data };
602
+ }
603
+ if (payload.errors) {
604
+ for (let [routeId, error] of Object.entries(payload.errors)) {
605
+ results.routes[routeId] = { error };
606
+ }
607
+ }
608
+ return { status: res.status, data: results };
609
+ } catch (e) {
610
+ throw new Error("Unable to decode RSC response");
611
+ }
612
+ };
613
+ }
614
+ function RSCHydratedRouter({
615
+ createFromReadableStream,
616
+ fetch: fetchImplementation = fetch,
617
+ payload,
618
+ routeDiscovery = "eager",
619
+ getContext
620
+ }) {
621
+ if (payload.type !== "render") throw new Error("Invalid payload type");
622
+ let { router: router2, routeModules } = React3.useMemo(
623
+ () => createRouterFromPayload({
624
+ payload,
625
+ fetchImplementation,
626
+ getContext,
627
+ createFromReadableStream
628
+ }),
629
+ [createFromReadableStream, payload, fetchImplementation, getContext]
630
+ );
631
+ React3.useEffect(() => {
632
+ setIsHydrated();
633
+ }, []);
634
+ React3.useLayoutEffect(() => {
635
+ const globalVar = window;
636
+ if (!globalVar.__routerInitialized) {
637
+ globalVar.__routerInitialized = true;
638
+ globalVar.__reactRouterDataRouter.initialize();
639
+ }
640
+ }, []);
641
+ let [location2, setLocation] = React3.useState(router2.state.location);
642
+ React3.useLayoutEffect(
643
+ () => router2.subscribe((newState) => {
644
+ if (newState.location !== location2) {
645
+ setLocation(newState.location);
646
+ }
647
+ }),
648
+ [router2, location2]
649
+ );
650
+ React3.useEffect(() => {
651
+ if (routeDiscovery === "lazy" || // @ts-expect-error - TS doesn't know about this yet
652
+ window.navigator?.connection?.saveData === true) {
653
+ return;
654
+ }
655
+ function registerElement(el) {
656
+ let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
657
+ if (!path) {
658
+ return;
659
+ }
660
+ let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
661
+ if (!discoveredPaths.has(pathname)) {
662
+ nextPaths.add(pathname);
663
+ }
664
+ }
665
+ async function fetchPatches() {
666
+ document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
667
+ let paths = Array.from(nextPaths.keys()).filter((path) => {
668
+ if (discoveredPaths.has(path)) {
669
+ nextPaths.delete(path);
670
+ return false;
671
+ }
672
+ return true;
673
+ });
674
+ if (paths.length === 0) {
675
+ return;
676
+ }
677
+ try {
678
+ await fetchAndApplyManifestPatches(
679
+ paths,
680
+ createFromReadableStream,
681
+ fetchImplementation
682
+ );
683
+ } catch (e) {
684
+ console.error("Failed to fetch manifest patches", e);
685
+ }
686
+ }
687
+ let debouncedFetchPatches = debounce(fetchPatches, 100);
688
+ fetchPatches();
689
+ let observer = new MutationObserver(() => debouncedFetchPatches());
690
+ observer.observe(document.documentElement, {
691
+ subtree: true,
692
+ childList: true,
693
+ attributes: true,
694
+ attributeFilter: ["data-discover", "href", "action"]
695
+ });
696
+ }, [routeDiscovery, createFromReadableStream, fetchImplementation]);
697
+ const frameworkContext = {
698
+ future: {
699
+ // These flags have no runtime impact so can always be false. If we add
700
+ // flags that drive runtime behavior they'll need to be proxied through.
701
+ v8_middleware: false,
702
+ unstable_subResourceIntegrity: false
703
+ },
704
+ isSpaMode: false,
705
+ ssr: true,
706
+ criticalCss: "",
707
+ manifest: {
708
+ routes: {},
709
+ version: "1",
710
+ url: "",
711
+ entry: {
712
+ module: "",
713
+ imports: []
714
+ }
715
+ },
716
+ routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
717
+ routeModules
718
+ };
719
+ return /* @__PURE__ */ React3.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React3.createElement(RSCRouterGlobalErrorBoundary, { location: location2 }, /* @__PURE__ */ React3.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React3.createElement(UNSTABLE_TransitionEnabledRouterProvider, { router: router2, flushSync: ReactDOM2.flushSync }))));
720
+ }
721
+ function createRouteFromServerManifest(match, payload) {
722
+ let hasInitialData = payload && match.id in payload.loaderData;
723
+ let initialData = payload?.loaderData[match.id];
724
+ let hasInitialError = payload?.errors && match.id in payload.errors;
725
+ let initialError = payload?.errors?.[match.id];
726
+ let isHydrationRequest = match.clientLoader?.hydrate === true || !match.hasLoader || // If the route has a component but we don't have an element, we need to hit
727
+ // the server loader flow regardless of whether the client loader calls
728
+ // `serverLoader` or not, otherwise we'll have nothing to render.
729
+ match.hasComponent && !match.element;
730
+ invariant(window.__reactRouterRouteModules);
731
+ populateRSCRouteModules(window.__reactRouterRouteModules, match);
732
+ let dataRoute = {
733
+ id: match.id,
734
+ element: match.element,
735
+ errorElement: match.errorElement,
736
+ handle: match.handle,
737
+ hasErrorBoundary: match.hasErrorBoundary,
738
+ hydrateFallbackElement: match.hydrateFallbackElement,
739
+ index: match.index,
740
+ loader: match.clientLoader ? async (args, singleFetch) => {
741
+ try {
742
+ let result = await match.clientLoader({
743
+ ...args,
744
+ serverLoader: () => {
745
+ preventInvalidServerHandlerCall(
746
+ "loader",
747
+ match.id,
748
+ match.hasLoader
749
+ );
750
+ if (isHydrationRequest) {
751
+ if (hasInitialData) {
752
+ return initialData;
753
+ }
754
+ if (hasInitialError) {
755
+ throw initialError;
756
+ }
757
+ }
758
+ return callSingleFetch(singleFetch);
759
+ }
760
+ });
761
+ return result;
762
+ } finally {
763
+ isHydrationRequest = false;
764
+ }
765
+ } : (
766
+ // We always make the call in this RSC world since even if we don't
767
+ // have a `loader` we may need to get the `element` implementation
768
+ (_, singleFetch) => callSingleFetch(singleFetch)
769
+ ),
770
+ action: match.clientAction ? (args, singleFetch) => match.clientAction({
771
+ ...args,
772
+ serverAction: async () => {
773
+ preventInvalidServerHandlerCall(
774
+ "action",
775
+ match.id,
776
+ match.hasLoader
777
+ );
778
+ return await callSingleFetch(singleFetch);
779
+ }
780
+ }) : match.hasAction ? (_, singleFetch) => callSingleFetch(singleFetch) : () => {
781
+ throw noActionDefinedError("action", match.id);
782
+ },
783
+ path: match.path,
784
+ shouldRevalidate: match.shouldRevalidate,
785
+ // We always have a "loader" in this RSC world since even if we don't
786
+ // have a `loader` we may need to get the `element` implementation
787
+ hasLoader: true,
788
+ hasClientLoader: match.clientLoader != null,
789
+ hasAction: match.hasAction,
790
+ hasClientAction: match.clientAction != null,
791
+ hasShouldRevalidate: match.shouldRevalidate != null
792
+ };
793
+ if (typeof dataRoute.loader === "function") {
794
+ dataRoute.loader.hydrate = shouldHydrateRouteLoader(
795
+ match.id,
796
+ match.clientLoader,
797
+ match.hasLoader,
798
+ false
799
+ );
800
+ }
801
+ return dataRoute;
802
+ }
803
+ function callSingleFetch(singleFetch) {
804
+ invariant(typeof singleFetch === "function", "Invalid singleFetch parameter");
805
+ return singleFetch();
806
+ }
807
+ function preventInvalidServerHandlerCall(type, routeId, hasHandler) {
808
+ if (!hasHandler) {
809
+ let fn = type === "action" ? "serverAction()" : "serverLoader()";
810
+ let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${routeId}")`;
811
+ console.error(msg);
812
+ throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
813
+ }
814
+ }
815
+ var nextPaths = /* @__PURE__ */ new Set();
816
+ var discoveredPathsMaxSize = 1e3;
817
+ var discoveredPaths = /* @__PURE__ */ new Set();
818
+ var URL_LIMIT = 7680;
819
+ function getManifestUrl(paths) {
820
+ if (paths.length === 0) {
821
+ return null;
822
+ }
823
+ if (paths.length === 1) {
824
+ return new URL(`${paths[0]}.manifest`, window.location.origin);
825
+ }
826
+ const globalVar = window;
827
+ let basename = (globalVar.__reactRouterDataRouter.basename ?? "").replace(
828
+ /^\/|\/$/g,
829
+ ""
830
+ );
831
+ let url = new URL(`${basename}/.manifest`, window.location.origin);
832
+ url.searchParams.set("paths", paths.sort().join(","));
833
+ return url;
834
+ }
835
+ async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fetchImplementation, signal) {
836
+ let url = getManifestUrl(paths);
837
+ if (url == null) {
838
+ return;
839
+ }
840
+ if (url.toString().length > URL_LIMIT) {
841
+ nextPaths.clear();
842
+ return;
843
+ }
844
+ let response = await fetchImplementation(new Request(url, { signal }));
845
+ if (!response.body || response.status < 200 || response.status >= 300) {
846
+ throw new Error("Unable to fetch new route matches from the server");
847
+ }
848
+ let payload = await createFromReadableStream(response.body, {
849
+ temporaryReferences: void 0
850
+ });
851
+ if (payload.type !== "manifest") {
852
+ throw new Error("Failed to patch routes");
853
+ }
854
+ paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
855
+ payload.patches.forEach((p) => {
856
+ window.__reactRouterDataRouter.patchRoutes(
857
+ p.parentId ?? null,
858
+ [createRouteFromServerManifest(p)]
859
+ );
860
+ });
861
+ }
862
+ function addToFifoQueue(path, queue) {
863
+ if (queue.size >= discoveredPathsMaxSize) {
864
+ let first = queue.values().next().value;
865
+ queue.delete(first);
866
+ }
867
+ queue.add(path);
868
+ }
869
+ function debounce(callback, wait) {
870
+ let timeoutId;
871
+ return (...args) => {
872
+ window.clearTimeout(timeoutId);
873
+ timeoutId = window.setTimeout(() => callback(...args), wait);
874
+ };
875
+ }
876
+ function isExternalLocation(location2) {
877
+ const newLocation = new URL(location2, window.location.href);
878
+ return newLocation.origin !== window.location.origin;
879
+ }
880
+
881
+ // lib/rsc/html-stream/browser.ts
882
+ function getRSCStream() {
883
+ let encoder = new TextEncoder();
884
+ let streamController = null;
885
+ let rscStream = new ReadableStream({
886
+ start(controller) {
887
+ if (typeof window === "undefined") {
888
+ return;
889
+ }
890
+ let handleChunk = (chunk) => {
891
+ if (typeof chunk === "string") {
892
+ controller.enqueue(encoder.encode(chunk));
893
+ } else {
894
+ controller.enqueue(chunk);
895
+ }
896
+ };
897
+ window.__FLIGHT_DATA || (window.__FLIGHT_DATA = []);
898
+ window.__FLIGHT_DATA.forEach(handleChunk);
899
+ window.__FLIGHT_DATA.push = (chunk) => {
900
+ handleChunk(chunk);
901
+ return 0;
902
+ };
903
+ streamController = controller;
904
+ }
905
+ });
906
+ if (typeof document !== "undefined" && document.readyState === "loading") {
907
+ document.addEventListener("DOMContentLoaded", () => {
908
+ streamController?.close();
909
+ });
910
+ } else {
911
+ streamController?.close();
912
+ }
913
+ return rscStream;
914
+ }
237
915
  export {
238
916
  HydratedRouter,
239
- RouterProvider2 as RouterProvider
917
+ RouterProvider2 as RouterProvider,
918
+ RSCHydratedRouter as unstable_RSCHydratedRouter,
919
+ createCallServer as unstable_createCallServer,
920
+ getRSCStream as unstable_getRSCStream
240
921
  };