react-router 0.0.0-experimental-3f68c7c20 → 0.0.0-experimental-e87ed2fd4

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 (39) hide show
  1. package/dist/development/{browser-BenyQgT4.d.mts → browser-C9OqCpRB.d.mts} +537 -136
  2. package/dist/development/{chunk-APN7PBP2.mjs → chunk-PVJCBITV.mjs} +65 -53
  3. package/dist/development/dom-export.d.mts +2 -2
  4. package/dist/development/dom-export.js +1 -1
  5. package/dist/development/dom-export.mjs +2 -2
  6. package/dist/development/index.d.mts +10 -390
  7. package/dist/development/index.d.ts +729 -708
  8. package/dist/development/index.js +68 -53
  9. package/dist/development/index.mjs +9 -3
  10. package/dist/development/lib/types/internal.d.mts +1 -1
  11. package/dist/development/lib/types/internal.d.ts +1 -1
  12. package/dist/development/lib/types/internal.js +1 -1
  13. package/dist/development/lib/types/internal.mjs +1 -1
  14. package/dist/{production/register-D3Ithcl4.d.ts → development/register-zy84znbA.d.ts} +1 -1
  15. package/dist/{production/route-data-CBHO1x2o.d.mts → development/route-data-C-cmsWVs.d.mts} +1 -1
  16. package/dist/development/rsc-export.d.mts +12 -1
  17. package/dist/development/rsc-export.d.ts +12 -1
  18. package/dist/development/rsc-export.js +209 -173
  19. package/dist/development/rsc-export.mjs +209 -174
  20. package/dist/production/{browser-BenyQgT4.d.mts → browser-C9OqCpRB.d.mts} +537 -136
  21. package/dist/production/{chunk-SAZGQ73S.mjs → chunk-FJS6IVQF.mjs} +65 -53
  22. package/dist/production/dom-export.d.mts +2 -2
  23. package/dist/production/dom-export.js +1 -1
  24. package/dist/production/dom-export.mjs +2 -2
  25. package/dist/production/index.d.mts +10 -390
  26. package/dist/production/index.d.ts +729 -708
  27. package/dist/production/index.js +68 -53
  28. package/dist/production/index.mjs +9 -3
  29. package/dist/production/lib/types/internal.d.mts +1 -1
  30. package/dist/production/lib/types/internal.d.ts +1 -1
  31. package/dist/production/lib/types/internal.js +1 -1
  32. package/dist/production/lib/types/internal.mjs +1 -1
  33. package/dist/{development/register-D3Ithcl4.d.ts → production/register-zy84znbA.d.ts} +1 -1
  34. package/dist/{development/route-data-CBHO1x2o.d.mts → production/route-data-C-cmsWVs.d.mts} +1 -1
  35. package/dist/production/rsc-export.d.mts +12 -1
  36. package/dist/production/rsc-export.d.ts +12 -1
  37. package/dist/production/rsc-export.js +209 -173
  38. package/dist/production/rsc-export.mjs +209 -174
  39. package/package.json +1 -1
@@ -25,7 +25,7 @@ function _interopNamespace(e) {
25
25
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
26
 
27
27
  /**
28
- * react-router v0.0.0-experimental-3f68c7c20
28
+ * react-router v0.0.0-experimental-e87ed2fd4
29
29
  *
30
30
  * Copyright (c) Remix Software Inc.
31
31
  *
@@ -106,6 +106,9 @@ function parsePath(path) {
106
106
  }
107
107
 
108
108
  // lib/router/utils.ts
109
+ function unstable_createContext(defaultValue) {
110
+ return { defaultValue };
111
+ }
109
112
  var _map;
110
113
  var unstable_RouterContextProvider = class {
111
114
  constructor(init) {
@@ -2368,7 +2371,19 @@ function createMemorySessionStorage({ cookie } = {}) {
2368
2371
  }
2369
2372
  });
2370
2373
  }
2371
- function getDocumentHeaders(context, getRouteHeadersFn) {
2374
+
2375
+ // lib/server-runtime/invariant.ts
2376
+ function invariant2(value, message) {
2377
+ if (value === false || value === null || typeof value === "undefined") {
2378
+ console.error(
2379
+ "The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose"
2380
+ );
2381
+ throw new Error(message);
2382
+ }
2383
+ }
2384
+
2385
+ // lib/server-runtime/headers.ts
2386
+ function getDocumentHeadersImpl(context, getRouteHeadersFn) {
2372
2387
  let boundaryIdx = context.errors ? context.matches.findIndex((m) => context.errors[m.route.id]) : -1;
2373
2388
  let matches = boundaryIdx >= 0 ? context.matches.slice(0, boundaryIdx + 1) : context.matches;
2374
2389
  let errorHeaders;
@@ -2430,16 +2445,6 @@ function prependCookies(parentHeaders, childHeaders) {
2430
2445
  }
2431
2446
  }
2432
2447
 
2433
- // lib/server-runtime/invariant.ts
2434
- function invariant2(value, message) {
2435
- if (value === false || value === null || typeof value === "undefined") {
2436
- console.error(
2437
- "The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose"
2438
- );
2439
- throw new Error(message);
2440
- }
2441
- }
2442
-
2443
2448
  // lib/rsc/server.rsc.ts
2444
2449
  async function matchRSCServerRequest({
2445
2450
  decodeCallServer,
@@ -2458,7 +2463,7 @@ async function matchRSCServerRequest({
2458
2463
  );
2459
2464
  return response2;
2460
2465
  }
2461
- let response = await getRenderPayload(
2466
+ let response = await generateRenderResponse(
2462
2467
  request,
2463
2468
  routes,
2464
2469
  decodeCallServer,
@@ -2471,24 +2476,27 @@ async function matchRSCServerRequest({
2471
2476
  }
2472
2477
  async function generateManifestResponse(routes, request, generateResponse) {
2473
2478
  let url = new URL(request.url);
2474
- const matches = matchRoutes(routes, url.pathname.replace(/\.manifest$/, ""));
2479
+ let matches = matchRoutes(routes, url.pathname.replace(/\.manifest$/, ""));
2480
+ let payload = {
2481
+ type: "manifest",
2482
+ matches: await Promise.all(
2483
+ matches?.map(
2484
+ (m, i) => getManifestRoute(m.route, matches[i - 1]?.route.id)
2485
+ ) ?? []
2486
+ ),
2487
+ patches: await getAdditionalRoutePatches(
2488
+ url.pathname,
2489
+ routes,
2490
+ matches?.map((m) => m.route.id) ?? []
2491
+ )
2492
+ };
2475
2493
  return generateResponse({
2476
2494
  statusCode: 200,
2477
2495
  headers: new Headers({
2478
2496
  "Content-Type": "text/x-component",
2479
2497
  Vary: "Content-Type"
2480
2498
  }),
2481
- payload: {
2482
- type: "manifest",
2483
- matches: await Promise.all(
2484
- matches?.map((m, i) => getRoute(m.route, matches[i - 1]?.route.id)) ?? []
2485
- ),
2486
- patches: await getAdditionalRoutePatches(
2487
- url.pathname,
2488
- routes,
2489
- matches?.map((m) => m.route.id) ?? []
2490
- )
2491
- }
2499
+ payload
2492
2500
  });
2493
2501
  }
2494
2502
  async function processServerAction(request, decodeCallServer, decodeFormAction, onError) {
@@ -2537,7 +2545,7 @@ async function processServerAction(request, decodeCallServer, decodeFormAction,
2537
2545
  }
2538
2546
  }
2539
2547
  }
2540
- async function getRenderPayload(request, routes, decodeCallServer, decodeFormAction, onError, generateResponse, actionResult) {
2548
+ async function generateRenderResponse(request, routes, decodeCallServer, decodeFormAction, onError, generateResponse) {
2541
2549
  let statusCode = 200;
2542
2550
  let url = new URL(request.url);
2543
2551
  let isDataRequest = request.headers.has("X-React-Router-Data-Request");
@@ -2548,22 +2556,12 @@ async function getRenderPayload(request, routes, decodeCallServer, decodeFormAct
2548
2556
  await Promise.all(matches.map((m) => explodeLazyRoute(m.route)));
2549
2557
  }
2550
2558
  const handler = createStaticHandler(routes);
2551
- const respond = (staticContext, actionResult2) => generateStaticContextResponse(
2552
- routes,
2553
- generateResponse,
2554
- statusCode,
2555
- routeIdsToLoad,
2556
- isDataRequest,
2557
- isSubmission,
2558
- actionResult2,
2559
- staticContext
2560
- );
2561
2559
  const result = await handler.query(request, {
2562
2560
  skipLoaderErrorBubbling: isDataRequest,
2563
2561
  skipRevalidation: isSubmission,
2564
2562
  ...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : null,
2565
- async unstable_stream(context, query) {
2566
- let actionResult2;
2563
+ async unstable_stream(_, query) {
2564
+ let actionResult;
2567
2565
  if (request.method === "POST") {
2568
2566
  let result2 = await processServerAction(
2569
2567
  request,
@@ -2571,7 +2569,7 @@ async function getRenderPayload(request, routes, decodeCallServer, decodeFormAct
2571
2569
  decodeFormAction,
2572
2570
  onError
2573
2571
  );
2574
- actionResult2 = result2?.actionResult;
2572
+ actionResult = result2?.actionResult;
2575
2573
  request = result2?.revalidationRequest ?? request;
2576
2574
  }
2577
2575
  let staticContext = await query(request);
@@ -2582,7 +2580,16 @@ async function getRenderPayload(request, routes, decodeCallServer, decodeFormAct
2582
2580
  generateResponse
2583
2581
  );
2584
2582
  }
2585
- return respond(staticContext, actionResult2);
2583
+ return generateStaticContextResponse(
2584
+ routes,
2585
+ generateResponse,
2586
+ statusCode,
2587
+ routeIdsToLoad,
2588
+ isDataRequest,
2589
+ isSubmission,
2590
+ actionResult,
2591
+ staticContext
2592
+ );
2586
2593
  }
2587
2594
  });
2588
2595
  if (isRedirectResponse(result)) {
@@ -2592,169 +2599,197 @@ async function getRenderPayload(request, routes, decodeCallServer, decodeFormAct
2592
2599
  return result;
2593
2600
  }
2594
2601
  function generateRedirectResponse(statusCode, response, generateResponse) {
2602
+ let payload = {
2603
+ type: "redirect",
2604
+ location: response.headers.get("Location") || "",
2605
+ reload: response.headers.get("X-Remix-Reload-Document") === "true",
2606
+ replace: response.headers.get("X-Remix-Replace") === "true",
2607
+ status: response.status
2608
+ };
2595
2609
  return generateResponse({
2596
2610
  statusCode,
2597
2611
  headers: new Headers({
2598
2612
  "Content-Type": "text/x-component",
2599
2613
  Vary: "Content-Type"
2600
2614
  }),
2601
- payload: {
2602
- type: "redirect",
2603
- location: response.headers.get("Location") || "",
2604
- reload: response.headers.get("X-Remix-Reload-Document") === "true",
2605
- replace: response.headers.get("X-Remix-Replace") === "true",
2606
- status: response.status
2607
- }
2615
+ payload
2608
2616
  });
2609
2617
  }
2610
2618
  async function generateStaticContextResponse(routes, generateResponse, statusCode, routeIdsToLoad, isDataRequest, isSubmission, actionResult, staticContext) {
2611
2619
  statusCode = staticContext.statusCode ?? statusCode;
2612
- const errors = staticContext.errors ? Object.fromEntries(
2613
- Object.entries(staticContext.errors).map(([key, error]) => [
2614
- key,
2615
- isRouteErrorResponse(error) ? Object.fromEntries(Object.entries(error)) : error
2616
- ])
2617
- ) : staticContext.errors;
2620
+ if (staticContext.errors) {
2621
+ staticContext.errors = Object.fromEntries(
2622
+ Object.entries(staticContext.errors).map(([key, error]) => [
2623
+ key,
2624
+ isRouteErrorResponse(error) ? Object.fromEntries(Object.entries(error)) : error
2625
+ ])
2626
+ );
2627
+ }
2618
2628
  staticContext.matches.forEach((m) => {
2619
2629
  if (staticContext.loaderData[m.route.id] === void 0) {
2620
2630
  staticContext.loaderData[m.route.id] = null;
2621
2631
  }
2622
2632
  });
2623
- let headers = getDocumentHeaders(
2633
+ let headers = getDocumentHeadersImpl(
2624
2634
  staticContext,
2625
2635
  (match) => match.route.headers
2626
2636
  );
2627
- const payload = {
2637
+ const baseRenderPayload = {
2628
2638
  type: "render",
2629
2639
  actionData: staticContext.actionData,
2630
- errors,
2640
+ errors: staticContext.errors,
2631
2641
  loaderData: staticContext.loaderData,
2632
2642
  location: staticContext.location
2633
2643
  };
2634
- if (!actionResult && isSubmission) {
2635
- return generateResponse({
2636
- statusCode,
2637
- headers,
2638
- payload: {
2639
- ...payload,
2640
- matches: [],
2641
- patches: []
2642
- }
2643
- });
2644
+ const renderPayloadPromise = () => getRenderPayload(
2645
+ baseRenderPayload,
2646
+ routes,
2647
+ routeIdsToLoad,
2648
+ isDataRequest,
2649
+ staticContext
2650
+ );
2651
+ let payload;
2652
+ if (actionResult) {
2653
+ payload = {
2654
+ type: "action",
2655
+ actionResult,
2656
+ rerender: renderPayloadPromise()
2657
+ };
2658
+ } else if (isSubmission && isDataRequest) {
2659
+ payload = {
2660
+ ...baseRenderPayload,
2661
+ matches: [],
2662
+ patches: []
2663
+ };
2664
+ } else {
2665
+ payload = await renderPayloadPromise();
2644
2666
  }
2645
- let lastMatch = null;
2667
+ return generateResponse({
2668
+ statusCode,
2669
+ headers,
2670
+ payload
2671
+ });
2672
+ }
2673
+ async function getRenderPayload(baseRenderPayload, routes, routeIdsToLoad, isDataRequest, staticContext) {
2674
+ let deepestRenderedRouteIdx = staticContext.matches.length - 1;
2675
+ let parentIds = {};
2676
+ staticContext.matches.forEach((m, i) => {
2677
+ if (i > 0) {
2678
+ parentIds[m.route.id] = staticContext.matches[i - 1].route.id;
2679
+ }
2680
+ if (staticContext.errors && m.route.id in staticContext.errors && deepestRenderedRouteIdx > i) {
2681
+ deepestRenderedRouteIdx = i;
2682
+ }
2683
+ });
2646
2684
  let matchesPromise = Promise.all(
2647
- staticContext.matches.map(async (match) => {
2648
- if ("lazy" in match.route && match.route.lazy) {
2649
- Object.assign(match.route, {
2650
- // @ts-expect-error - FIXME: Fix the types here
2651
- ...await match.route.lazy(),
2652
- path: match.route.path,
2653
- index: match.route.index,
2654
- id: match.route.id
2655
- });
2656
- match.route.lazy = void 0;
2657
- }
2658
- const Layout = match.route.Layout || React__namespace.Fragment;
2659
- const Component = match.route.default;
2660
- const ErrorBoundary = match.route.ErrorBoundary;
2661
- const HydrateFallback = match.route.HydrateFallback;
2662
- const loaderData = staticContext.loaderData[match.route.id];
2663
- const actionData = staticContext.actionData?.[match.route.id];
2664
- const params = match.params;
2665
- const element = Component ? staticContext.errors?.[match.route.id] ? false : React__namespace.createElement(
2666
- Layout,
2667
- null,
2668
- React__namespace.createElement(Component, {
2669
- loaderData,
2670
- actionData,
2671
- params,
2672
- matches: staticContext.matches.map(
2673
- (match2) => convertRouteMatchToUiMatch(match2, staticContext.loaderData)
2674
- )
2675
- })
2676
- ) : void 0;
2677
- const errorElement = ErrorBoundary ? React__namespace.createElement(
2678
- Layout,
2679
- null,
2680
- React__namespace.createElement(ErrorBoundary, {
2681
- loaderData,
2682
- actionData,
2683
- params,
2684
- error: [...staticContext.matches].reverse().find((match2) => staticContext.errors?.[match2.route.id])
2685
- })
2686
- ) : void 0;
2687
- const hydrateFallbackElement = HydrateFallback ? React__namespace.createElement(
2688
- Layout,
2689
- null,
2690
- React__namespace.createElement(HydrateFallback, {
2691
- loaderData,
2692
- actionData,
2693
- params
2694
- })
2695
- ) : match.route.id === "root" ? (
2696
- // FIXME: This should use the `RemixRootDefaultErrorBoundary` but that
2697
- // currently uses a hook internally so it fails during RSC. Restructure
2698
- // so it can be used safely in an RSC render pass.
2699
- React__namespace.createElement("p", null, "Loading!")
2700
- ) : void 0;
2701
- let result = {
2702
- clientAction: match.route.clientAction,
2703
- clientLoader: match.route.clientLoader,
2704
- element,
2705
- errorElement,
2706
- handle: match.route.handle,
2707
- hasAction: !!match.route.action,
2708
- hasErrorBoundary: !!match.route.ErrorBoundary,
2709
- hasLoader: !!match.route.loader,
2710
- hydrateFallbackElement,
2711
- id: match.route.id,
2712
- index: match.route.index,
2713
- links: match.route.links,
2714
- meta: match.route.meta,
2715
- params,
2716
- parentId: lastMatch?.route.id,
2717
- path: match.route.path,
2718
- pathname: match.pathname,
2719
- pathnameBase: match.pathnameBase,
2720
- shouldRevalidate: match.route.shouldRevalidate
2721
- };
2722
- lastMatch = match;
2723
- return result;
2685
+ staticContext.matches.map((match, i) => {
2686
+ let shouldRenderComponent = i <= deepestRenderedRouteIdx && (!routeIdsToLoad || routeIdsToLoad.includes(match.route.id)) && (!staticContext.errors || !(match.route.id in staticContext.errors));
2687
+ return getServerRouteMatch(
2688
+ staticContext,
2689
+ match,
2690
+ shouldRenderComponent,
2691
+ parentIds[match.route.id]
2692
+ );
2724
2693
  })
2725
2694
  );
2726
- const getPayload = async () => {
2727
- const matches = await matchesPromise;
2728
- return {
2729
- ...payload,
2730
- matches: routeIdsToLoad ? matches.filter((m) => routeIdsToLoad.includes(m.id)) : matches,
2731
- patches: !isDataRequest ? await getAdditionalRoutePatches(
2732
- staticContext.location.pathname,
2733
- routes,
2734
- matches.map((m) => m.id)
2735
- ) : void 0
2736
- };
2695
+ let patchesPromise = !isDataRequest ? getAdditionalRoutePatches(
2696
+ staticContext.location.pathname,
2697
+ routes,
2698
+ staticContext.matches.map((m) => m.route.id)
2699
+ ) : void 0;
2700
+ let [matches, patches] = await Promise.all([matchesPromise, patchesPromise]);
2701
+ return {
2702
+ ...baseRenderPayload,
2703
+ matches,
2704
+ patches
2737
2705
  };
2738
- if (actionResult) {
2739
- return generateResponse({
2740
- statusCode,
2741
- headers,
2742
- payload: {
2743
- type: "action",
2744
- actionResult,
2745
- rerender: getPayload()
2746
- }
2747
- });
2748
- } else {
2749
- let payload2 = await getPayload();
2750
- return generateResponse({
2751
- statusCode,
2752
- headers,
2753
- payload: payload2
2706
+ }
2707
+ async function getServerRouteMatch(staticContext, match, shouldRenderComponent, parentId) {
2708
+ if ("lazy" in match.route && match.route.lazy) {
2709
+ Object.assign(match.route, {
2710
+ // @ts-expect-error - FIXME: Fix the types here
2711
+ ...await match.route.lazy(),
2712
+ path: match.route.path,
2713
+ index: match.route.index,
2714
+ id: match.route.id
2754
2715
  });
2716
+ match.route.lazy = void 0;
2717
+ }
2718
+ const Layout = match.route.Layout || React__namespace.Fragment;
2719
+ const Component = match.route.default;
2720
+ const ErrorBoundary = match.route.ErrorBoundary;
2721
+ const HydrateFallback = match.route.HydrateFallback;
2722
+ const loaderData = staticContext.loaderData[match.route.id];
2723
+ const actionData = staticContext.actionData?.[match.route.id];
2724
+ const params = match.params;
2725
+ const element = Component && shouldRenderComponent ? React__namespace.createElement(
2726
+ Layout,
2727
+ null,
2728
+ React__namespace.createElement(Component, {
2729
+ loaderData,
2730
+ actionData,
2731
+ params,
2732
+ matches: staticContext.matches.map(
2733
+ (match2) => convertRouteMatchToUiMatch(match2, staticContext.loaderData)
2734
+ )
2735
+ })
2736
+ ) : void 0;
2737
+ let error = void 0;
2738
+ if (ErrorBoundary && staticContext.errors) {
2739
+ for (const match2 of [...staticContext.matches].reverse()) {
2740
+ if (match2.route.id in staticContext.errors) {
2741
+ error = staticContext.errors[match2.route.id];
2742
+ break;
2743
+ }
2744
+ }
2755
2745
  }
2746
+ const errorElement = ErrorBoundary ? React__namespace.createElement(
2747
+ Layout,
2748
+ null,
2749
+ React__namespace.createElement(ErrorBoundary, {
2750
+ loaderData,
2751
+ actionData,
2752
+ params,
2753
+ error
2754
+ })
2755
+ ) : void 0;
2756
+ const hydrateFallbackElement = HydrateFallback ? React__namespace.createElement(
2757
+ Layout,
2758
+ null,
2759
+ React__namespace.createElement(HydrateFallback, {
2760
+ loaderData,
2761
+ actionData,
2762
+ params
2763
+ })
2764
+ ) : match.route.id === "root" ? (
2765
+ // FIXME: This should use the `RemixRootDefaultErrorBoundary` but that
2766
+ // currently uses a hook internally so it fails during RSC. Restructure
2767
+ // so it can be used safely in an RSC render pass.
2768
+ React__namespace.createElement("p", null, "Loading!")
2769
+ ) : void 0;
2770
+ return {
2771
+ clientAction: match.route.clientAction,
2772
+ clientLoader: match.route.clientLoader,
2773
+ element,
2774
+ errorElement,
2775
+ handle: match.route.handle,
2776
+ hasAction: !!match.route.action,
2777
+ hasErrorBoundary: !!match.route.ErrorBoundary,
2778
+ hasLoader: !!match.route.loader,
2779
+ hydrateFallbackElement,
2780
+ id: match.route.id,
2781
+ index: match.route.index,
2782
+ links: match.route.links,
2783
+ meta: match.route.meta,
2784
+ params,
2785
+ parentId,
2786
+ path: match.route.path,
2787
+ pathname: match.pathname,
2788
+ pathnameBase: match.pathnameBase,
2789
+ shouldRevalidate: match.route.shouldRevalidate
2790
+ };
2756
2791
  }
2757
- async function getRoute(route, parentId) {
2792
+ async function getManifestRoute(route, parentId) {
2758
2793
  await explodeLazyRoute(route);
2759
2794
  const Layout = route.Layout || React__namespace.Fragment;
2760
2795
  const errorElement = route.ErrorBoundary ? React__namespace.createElement(
@@ -2806,7 +2841,7 @@ async function getAdditionalRoutePatches(pathname, routes, matchedRouteIds) {
2806
2841
  );
2807
2842
  });
2808
2843
  let patches = await Promise.all(
2809
- [...patchRouteMatches.values()].filter((route) => !matchedRouteIds.some((id) => id === route.id)).map((route) => getRoute(route, route.parentId))
2844
+ [...patchRouteMatches.values()].filter((route) => !matchedRouteIds.some((id) => id === route.id)).map((route) => getManifestRoute(route, route.parentId))
2810
2845
  );
2811
2846
  return patches;
2812
2847
  }
@@ -2832,3 +2867,4 @@ exports.matchRoutes = matchRoutes;
2832
2867
  exports.redirect = redirect;
2833
2868
  exports.redirectDocument = redirectDocument;
2834
2869
  exports.replace = replace;
2870
+ exports.unstable_createContext = unstable_createContext;