react-router 0.0.0-experimental-e0b6ce9 → 0.0.0-experimental-de3b900

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