@remix-run/router 1.8.0-pre.0 → 1.9.0-pre.0

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/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # `@remix-run/router`
2
2
 
3
- ## 1.8.0-pre.0
3
+ ## 1.9.0-pre.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Removed internal API only required for the Remix v1 back-compat layer and no longer needed in Remix v2 (`_isFetchActionRedirect`, `_hasFetcherDoneAnything`) ([#10715](https://github.com/remix-run/react-router/pull/10715))
8
+
9
+ ### Patch Changes
10
+
11
+ - Add method/url to error message on aborted `query`/`queryRoute` calls ([#10793](https://github.com/remix-run/react-router/pull/10793))
12
+ - Move the `@private` class export `ErrorResponse` to an `UNSAFE_ErrorResponseImpl` export since it is an implementation detail and there should be no construction of `ErrorResponse` instances in userland. This frees us up to export a `type ErrorResponse` which correlates to an instance of the class via `InstanceType`. Userland code should only ever be using `ErrorResponse` as a type and should be type-narrowing via `isRouteErrorResponse`. ([#10811](https://github.com/remix-run/react-router/pull/10811))
13
+ - Export `ShouldRevalidateFunctionArgs` interface ([#10797](https://github.com/remix-run/react-router/pull/10797))
14
+ - Fix a race-condition with loader/action-thrown errors on `route.lazy` routes ([#10778](https://github.com/remix-run/react-router/pull/10778))
15
+ - Fix type for `actionResult` on the arguments object passed to `shouldRevalidate` ([#10779](https://github.com/remix-run/react-router/pull/10779))
16
+
17
+ ## 1.8.0
4
18
 
5
19
  ### Minor Changes
6
20
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, LazyRouteFunction, TrackedPromise, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, V7_FormMethod, } from "./utils";
2
- export { AbortedDeferredError, ErrorResponse, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, resolvePath, resolveTo, stripBasename, } from "./utils";
1
+ export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, V7_FormMethod, } from "./utils";
2
+ export { AbortedDeferredError, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, resolvePath, resolveTo, stripBasename, } from "./utils";
3
3
  export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
4
- export { Action, createBrowserHistory, createPath, createHashHistory, createMemoryHistory, parsePath, } from "./history";
4
+ export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath, } from "./history";
5
5
  export * from "./router";
6
6
  /** @internal */
7
7
  export type { RouteManifest as UNSAFE_RouteManifest } from "./utils";
8
- export { DeferredData as UNSAFE_DeferredData, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, } from "./utils";
8
+ export { DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, } from "./utils";
9
9
  export { invariant as UNSAFE_invariant, warning as UNSAFE_warning, } from "./history";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.8.0-pre.0
2
+ * @remix-run/router v1.9.0-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -627,6 +627,10 @@ let ResultType = /*#__PURE__*/function (ResultType) {
627
627
  * Route action function signature
628
628
  */
629
629
 
630
+ /**
631
+ * Arguments passed to shouldRevalidate function
632
+ */
633
+
630
634
  /**
631
635
  * Route shouldRevalidate function signature. This runs after any submission
632
636
  * (navigation or fetcher), so we flatten the navigation/fetcher submission
@@ -1465,7 +1469,7 @@ const redirectDocument = (url, init) => {
1465
1469
  * @private
1466
1470
  * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
1467
1471
  */
1468
- class ErrorResponse {
1472
+ class ErrorResponseImpl {
1469
1473
  constructor(status, statusText, data, internal) {
1470
1474
  if (internal === void 0) {
1471
1475
  internal = false;
@@ -1482,6 +1486,9 @@ class ErrorResponse {
1482
1486
  }
1483
1487
  }
1484
1488
 
1489
+ // We don't want the class exported since usage of it at runtime is an
1490
+ // implementation detail, but we do want to export the shape so folks can
1491
+ // build their own abstractions around instances via isRouteErrorResponse()
1485
1492
  /**
1486
1493
  * Check if the given error is an ErrorResponse generated from a 4xx/5xx
1487
1494
  * Response thrown from an action/loader
@@ -2466,8 +2473,7 @@ function createRouter(init) {
2466
2473
  fetchers: new Map(state.fetchers)
2467
2474
  });
2468
2475
  return startRedirectNavigation(state, actionResult, {
2469
- submission,
2470
- isFetchActionRedirect: true
2476
+ fetcherSubmission: submission
2471
2477
  });
2472
2478
  }
2473
2479
  }
@@ -2682,18 +2688,15 @@ function createRouter(init) {
2682
2688
  async function startRedirectNavigation(state, redirect, _temp) {
2683
2689
  let {
2684
2690
  submission,
2685
- replace,
2686
- isFetchActionRedirect
2691
+ fetcherSubmission,
2692
+ replace
2687
2693
  } = _temp === void 0 ? {} : _temp;
2688
2694
  if (redirect.revalidate) {
2689
2695
  isRevalidationRequired = true;
2690
2696
  }
2691
- let redirectLocation = createLocation(state.location, redirect.location, // TODO: This can be removed once we get rid of useTransition in Remix v2
2692
- _extends({
2697
+ let redirectLocation = createLocation(state.location, redirect.location, {
2693
2698
  _isRedirect: true
2694
- }, isFetchActionRedirect ? {
2695
- _isFetchActionRedirect: true
2696
- } : {}));
2699
+ });
2697
2700
  invariant(redirectLocation, "Expected a location on the redirect navigation");
2698
2701
  if (isBrowser) {
2699
2702
  let isDocumentReload = false;
@@ -2725,11 +2728,19 @@ function createRouter(init) {
2725
2728
 
2726
2729
  // Use the incoming submission if provided, fallback on the active one in
2727
2730
  // state.navigation
2728
- let activeSubmission = submission || getSubmissionFromNavigation(state.navigation);
2731
+ let {
2732
+ formMethod,
2733
+ formAction,
2734
+ formEncType
2735
+ } = state.navigation;
2736
+ if (!submission && !fetcherSubmission && formMethod && formAction && formEncType) {
2737
+ submission = getSubmissionFromNavigation(state.navigation);
2738
+ }
2729
2739
 
2730
2740
  // If this was a 307/308 submission we want to preserve the HTTP method and
2731
2741
  // re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the
2732
2742
  // redirected location
2743
+ let activeSubmission = submission || fetcherSubmission;
2733
2744
  if (redirectPreserveMethodStatusCodes.has(redirect.status) && activeSubmission && isMutationMethod(activeSubmission.formMethod)) {
2734
2745
  await startNavigation(redirectHistoryAction, redirectLocation, {
2735
2746
  submission: _extends({}, activeSubmission, {
@@ -2738,20 +2749,14 @@ function createRouter(init) {
2738
2749
  // Preserve this flag across redirects
2739
2750
  preventScrollReset: pendingPreventScrollReset
2740
2751
  });
2741
- } else if (isFetchActionRedirect) {
2742
- // For a fetch action redirect, we kick off a new loading navigation
2743
- // without the fetcher submission, but we send it along for shouldRevalidate
2744
- await startNavigation(redirectHistoryAction, redirectLocation, {
2745
- overrideNavigation: getLoadingNavigation(redirectLocation),
2746
- fetcherSubmission: activeSubmission,
2747
- // Preserve this flag across redirects
2748
- preventScrollReset: pendingPreventScrollReset
2749
- });
2750
2752
  } else {
2751
- // If we have a submission, we will preserve it through the redirect navigation
2752
- let overrideNavigation = getLoadingNavigation(redirectLocation, activeSubmission);
2753
+ // If we have a navigation submission, we will preserve it through the
2754
+ // redirect navigation
2755
+ let overrideNavigation = getLoadingNavigation(redirectLocation, submission);
2753
2756
  await startNavigation(redirectHistoryAction, redirectLocation, {
2754
2757
  overrideNavigation,
2758
+ // Send fetcher submissions through for shouldRevalidate
2759
+ fetcherSubmission,
2755
2760
  // Preserve this flag across redirects
2756
2761
  preventScrollReset: pendingPreventScrollReset
2757
2762
  });
@@ -3270,7 +3275,7 @@ function createStaticHandler(routes, opts) {
3270
3275
  });
3271
3276
  if (request.signal.aborted) {
3272
3277
  let method = isRouteRequest ? "queryRoute" : "query";
3273
- throw new Error(method + "() call aborted");
3278
+ throw new Error(method + "() call aborted: " + request.method + " " + request.url);
3274
3279
  }
3275
3280
  }
3276
3281
  if (isRedirectResult(result)) {
@@ -3389,7 +3394,7 @@ function createStaticHandler(routes, opts) {
3389
3394
  }))]);
3390
3395
  if (request.signal.aborted) {
3391
3396
  let method = isRouteRequest ? "queryRoute" : "query";
3392
- throw new Error(method + "() call aborted");
3397
+ throw new Error(method + "() call aborted: " + request.method + " " + request.url);
3393
3398
  }
3394
3399
 
3395
3400
  // Process and commit output from loaders
@@ -3846,7 +3851,17 @@ async function callLoaderOrAction(type, request, match, matches, manifest, mapRo
3846
3851
  if (match.route.lazy) {
3847
3852
  if (handler) {
3848
3853
  // Run statically defined handler in parallel with lazy()
3849
- let values = await Promise.all([runHandler(handler), loadLazyRouteModule(match.route, mapRouteProperties, manifest)]);
3854
+ let handlerError;
3855
+ let values = await Promise.all([
3856
+ // If the handler throws, don't let it immediately bubble out,
3857
+ // since we need to let the lazy() execution finish so we know if this
3858
+ // route has a boundary that can handle the error
3859
+ runHandler(handler).catch(e => {
3860
+ handlerError = e;
3861
+ }), loadLazyRouteModule(match.route, mapRouteProperties, manifest)]);
3862
+ if (handlerError) {
3863
+ throw handlerError;
3864
+ }
3850
3865
  result = values[0];
3851
3866
  } else {
3852
3867
  // Load lazy route module, then run any returned handler
@@ -3954,7 +3969,7 @@ async function callLoaderOrAction(type, request, match, matches, manifest, mapRo
3954
3969
  if (resultType === ResultType.error) {
3955
3970
  return {
3956
3971
  type: resultType,
3957
- error: new ErrorResponse(status, result.statusText, data),
3972
+ error: new ErrorResponseImpl(status, result.statusText, data),
3958
3973
  headers: result.headers
3959
3974
  };
3960
3975
  }
@@ -4233,7 +4248,7 @@ function getInternalRouterError(status, _temp4) {
4233
4248
  errorMessage = "Invalid request method \"" + method.toUpperCase() + "\"";
4234
4249
  }
4235
4250
  }
4236
- return new ErrorResponse(status || 500, statusText, new Error(errorMessage), true);
4251
+ return new ErrorResponseImpl(status || 500, statusText, new Error(errorMessage), true);
4237
4252
  }
4238
4253
 
4239
4254
  // Find any returned redirect errors, starting from the lowest match
@@ -4481,8 +4496,7 @@ function getLoadingFetcher(submission, data) {
4481
4496
  formData: submission.formData,
4482
4497
  json: submission.json,
4483
4498
  text: submission.text,
4484
- data,
4485
- " _hasFetcherDoneAnything ": true
4499
+ data
4486
4500
  };
4487
4501
  return fetcher;
4488
4502
  } else {
@@ -4494,8 +4508,7 @@ function getLoadingFetcher(submission, data) {
4494
4508
  formData: undefined,
4495
4509
  json: undefined,
4496
4510
  text: undefined,
4497
- data,
4498
- " _hasFetcherDoneAnything ": true
4511
+ data
4499
4512
  };
4500
4513
  return fetcher;
4501
4514
  }
@@ -4509,8 +4522,7 @@ function getSubmittingFetcher(submission, existingFetcher) {
4509
4522
  formData: submission.formData,
4510
4523
  json: submission.json,
4511
4524
  text: submission.text,
4512
- data: existingFetcher ? existingFetcher.data : undefined,
4513
- " _hasFetcherDoneAnything ": true
4525
+ data: existingFetcher ? existingFetcher.data : undefined
4514
4526
  };
4515
4527
  return fetcher;
4516
4528
  }
@@ -4523,8 +4535,7 @@ function getDoneFetcher(data) {
4523
4535
  formData: undefined,
4524
4536
  json: undefined,
4525
4537
  text: undefined,
4526
- data,
4527
- " _hasFetcherDoneAnything ": true
4538
+ data
4528
4539
  };
4529
4540
  return fetcher;
4530
4541
  }
@@ -4532,12 +4543,12 @@ function getDoneFetcher(data) {
4532
4543
 
4533
4544
  exports.AbortedDeferredError = AbortedDeferredError;
4534
4545
  exports.Action = Action;
4535
- exports.ErrorResponse = ErrorResponse;
4536
4546
  exports.IDLE_BLOCKER = IDLE_BLOCKER;
4537
4547
  exports.IDLE_FETCHER = IDLE_FETCHER;
4538
4548
  exports.IDLE_NAVIGATION = IDLE_NAVIGATION;
4539
4549
  exports.UNSAFE_DEFERRED_SYMBOL = UNSAFE_DEFERRED_SYMBOL;
4540
4550
  exports.UNSAFE_DeferredData = DeferredData;
4551
+ exports.UNSAFE_ErrorResponseImpl = ErrorResponseImpl;
4541
4552
  exports.UNSAFE_convertRoutesToDataRoutes = convertRoutesToDataRoutes;
4542
4553
  exports.UNSAFE_getPathContributingMatches = getPathContributingMatches;
4543
4554
  exports.UNSAFE_invariant = invariant;