@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/dist/router.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { History, Location, Path, To } from "./history";
2
2
  import { Action as HistoryAction } from "./history";
3
- import type { DeferredData, AgnosticDataRouteMatch, AgnosticDataRouteObject, FormEncType, DetectErrorBoundaryFunction, RouteData, AgnosticRouteObject, Submission, AgnosticRouteMatch, HTMLFormMethod, MapRoutePropertiesFunction } from "./utils";
3
+ import type { AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DeferredData, DetectErrorBoundaryFunction, FormEncType, HTMLFormMethod, MapRoutePropertiesFunction, RouteData, Submission } from "./utils";
4
4
  /**
5
5
  * A Router instance manages all navigation and data loading/mutations
6
6
  */
@@ -407,7 +407,6 @@ type FetcherStates<TData = any> = {
407
407
  formData: undefined;
408
408
  json: undefined;
409
409
  data: TData | undefined;
410
- " _hasFetcherDoneAnything "?: boolean;
411
410
  };
412
411
  Loading: {
413
412
  state: "loading";
@@ -418,7 +417,6 @@ type FetcherStates<TData = any> = {
418
417
  formData: Submission["formData"] | undefined;
419
418
  json: Submission["json"] | undefined;
420
419
  data: TData | undefined;
421
- " _hasFetcherDoneAnything "?: boolean;
422
420
  };
423
421
  Submitting: {
424
422
  state: "submitting";
@@ -429,7 +427,6 @@ type FetcherStates<TData = any> = {
429
427
  formData: Submission["formData"];
430
428
  json: Submission["json"];
431
429
  data: TData | undefined;
432
- " _hasFetcherDoneAnything "?: boolean;
433
430
  };
434
431
  };
435
432
  export type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
package/dist/router.js CHANGED
@@ -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
  *
@@ -1190,7 +1190,7 @@ const redirectDocument = (url, init) => {
1190
1190
  * @private
1191
1191
  * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
1192
1192
  */
1193
- class ErrorResponse {
1193
+ class ErrorResponseImpl {
1194
1194
  constructor(status, statusText, data, internal) {
1195
1195
  if (internal === void 0) {
1196
1196
  internal = false;
@@ -2050,8 +2050,7 @@ function createRouter(init) {
2050
2050
  fetchers: new Map(state.fetchers)
2051
2051
  });
2052
2052
  return startRedirectNavigation(state, actionResult, {
2053
- submission,
2054
- isFetchActionRedirect: true
2053
+ fetcherSubmission: submission
2055
2054
  });
2056
2055
  }
2057
2056
  }
@@ -2252,18 +2251,15 @@ function createRouter(init) {
2252
2251
  async function startRedirectNavigation(state, redirect, _temp) {
2253
2252
  let {
2254
2253
  submission,
2255
- replace,
2256
- isFetchActionRedirect
2254
+ fetcherSubmission,
2255
+ replace
2257
2256
  } = _temp === void 0 ? {} : _temp;
2258
2257
  if (redirect.revalidate) {
2259
2258
  isRevalidationRequired = true;
2260
2259
  }
2261
- let redirectLocation = createLocation(state.location, redirect.location, // TODO: This can be removed once we get rid of useTransition in Remix v2
2262
- _extends({
2260
+ let redirectLocation = createLocation(state.location, redirect.location, {
2263
2261
  _isRedirect: true
2264
- }, isFetchActionRedirect ? {
2265
- _isFetchActionRedirect: true
2266
- } : {}));
2262
+ });
2267
2263
  invariant(redirectLocation, "Expected a location on the redirect navigation");
2268
2264
  if (isBrowser) {
2269
2265
  let isDocumentReload = false;
@@ -2293,10 +2289,18 @@ function createRouter(init) {
2293
2289
  let redirectHistoryAction = replace === true ? Action.Replace : Action.Push;
2294
2290
  // Use the incoming submission if provided, fallback on the active one in
2295
2291
  // state.navigation
2296
- let activeSubmission = submission || getSubmissionFromNavigation(state.navigation);
2292
+ let {
2293
+ formMethod,
2294
+ formAction,
2295
+ formEncType
2296
+ } = state.navigation;
2297
+ if (!submission && !fetcherSubmission && formMethod && formAction && formEncType) {
2298
+ submission = getSubmissionFromNavigation(state.navigation);
2299
+ }
2297
2300
  // If this was a 307/308 submission we want to preserve the HTTP method and
2298
2301
  // re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the
2299
2302
  // redirected location
2303
+ let activeSubmission = submission || fetcherSubmission;
2300
2304
  if (redirectPreserveMethodStatusCodes.has(redirect.status) && activeSubmission && isMutationMethod(activeSubmission.formMethod)) {
2301
2305
  await startNavigation(redirectHistoryAction, redirectLocation, {
2302
2306
  submission: _extends({}, activeSubmission, {
@@ -2305,20 +2309,14 @@ function createRouter(init) {
2305
2309
  // Preserve this flag across redirects
2306
2310
  preventScrollReset: pendingPreventScrollReset
2307
2311
  });
2308
- } else if (isFetchActionRedirect) {
2309
- // For a fetch action redirect, we kick off a new loading navigation
2310
- // without the fetcher submission, but we send it along for shouldRevalidate
2311
- await startNavigation(redirectHistoryAction, redirectLocation, {
2312
- overrideNavigation: getLoadingNavigation(redirectLocation),
2313
- fetcherSubmission: activeSubmission,
2314
- // Preserve this flag across redirects
2315
- preventScrollReset: pendingPreventScrollReset
2316
- });
2317
2312
  } else {
2318
- // If we have a submission, we will preserve it through the redirect navigation
2319
- let overrideNavigation = getLoadingNavigation(redirectLocation, activeSubmission);
2313
+ // If we have a navigation submission, we will preserve it through the
2314
+ // redirect navigation
2315
+ let overrideNavigation = getLoadingNavigation(redirectLocation, submission);
2320
2316
  await startNavigation(redirectHistoryAction, redirectLocation, {
2321
2317
  overrideNavigation,
2318
+ // Send fetcher submissions through for shouldRevalidate
2319
+ fetcherSubmission,
2322
2320
  // Preserve this flag across redirects
2323
2321
  preventScrollReset: pendingPreventScrollReset
2324
2322
  });
@@ -2821,7 +2819,7 @@ function createStaticHandler(routes, opts) {
2821
2819
  });
2822
2820
  if (request.signal.aborted) {
2823
2821
  let method = isRouteRequest ? "queryRoute" : "query";
2824
- throw new Error(method + "() call aborted");
2822
+ throw new Error(method + "() call aborted: " + request.method + " " + request.url);
2825
2823
  }
2826
2824
  }
2827
2825
  if (isRedirectResult(result)) {
@@ -2936,7 +2934,7 @@ function createStaticHandler(routes, opts) {
2936
2934
  }))]);
2937
2935
  if (request.signal.aborted) {
2938
2936
  let method = isRouteRequest ? "queryRoute" : "query";
2939
- throw new Error(method + "() call aborted");
2937
+ throw new Error(method + "() call aborted: " + request.method + " " + request.url);
2940
2938
  }
2941
2939
  // Process and commit output from loaders
2942
2940
  let activeDeferreds = new Map();
@@ -3367,7 +3365,17 @@ async function callLoaderOrAction(type, request, match, matches, manifest, mapRo
3367
3365
  if (match.route.lazy) {
3368
3366
  if (handler) {
3369
3367
  // Run statically defined handler in parallel with lazy()
3370
- let values = await Promise.all([runHandler(handler), loadLazyRouteModule(match.route, mapRouteProperties, manifest)]);
3368
+ let handlerError;
3369
+ let values = await Promise.all([
3370
+ // If the handler throws, don't let it immediately bubble out,
3371
+ // since we need to let the lazy() execution finish so we know if this
3372
+ // route has a boundary that can handle the error
3373
+ runHandler(handler).catch(e => {
3374
+ handlerError = e;
3375
+ }), loadLazyRouteModule(match.route, mapRouteProperties, manifest)]);
3376
+ if (handlerError) {
3377
+ throw handlerError;
3378
+ }
3371
3379
  result = values[0];
3372
3380
  } else {
3373
3381
  // Load lazy route module, then run any returned handler
@@ -3471,7 +3479,7 @@ async function callLoaderOrAction(type, request, match, matches, manifest, mapRo
3471
3479
  if (resultType === ResultType.error) {
3472
3480
  return {
3473
3481
  type: resultType,
3474
- error: new ErrorResponse(status, result.statusText, data),
3482
+ error: new ErrorResponseImpl(status, result.statusText, data),
3475
3483
  headers: result.headers
3476
3484
  };
3477
3485
  }
@@ -3740,7 +3748,7 @@ function getInternalRouterError(status, _temp4) {
3740
3748
  errorMessage = "Invalid request method \"" + method.toUpperCase() + "\"";
3741
3749
  }
3742
3750
  }
3743
- return new ErrorResponse(status || 500, statusText, new Error(errorMessage), true);
3751
+ return new ErrorResponseImpl(status || 500, statusText, new Error(errorMessage), true);
3744
3752
  }
3745
3753
  // Find any returned redirect errors, starting from the lowest match
3746
3754
  function findRedirect(results) {
@@ -3985,8 +3993,7 @@ function getLoadingFetcher(submission, data) {
3985
3993
  formData: submission.formData,
3986
3994
  json: submission.json,
3987
3995
  text: submission.text,
3988
- data,
3989
- " _hasFetcherDoneAnything ": true
3996
+ data
3990
3997
  };
3991
3998
  return fetcher;
3992
3999
  } else {
@@ -3998,8 +4005,7 @@ function getLoadingFetcher(submission, data) {
3998
4005
  formData: undefined,
3999
4006
  json: undefined,
4000
4007
  text: undefined,
4001
- data,
4002
- " _hasFetcherDoneAnything ": true
4008
+ data
4003
4009
  };
4004
4010
  return fetcher;
4005
4011
  }
@@ -4013,8 +4019,7 @@ function getSubmittingFetcher(submission, existingFetcher) {
4013
4019
  formData: submission.formData,
4014
4020
  json: submission.json,
4015
4021
  text: submission.text,
4016
- data: existingFetcher ? existingFetcher.data : undefined,
4017
- " _hasFetcherDoneAnything ": true
4022
+ data: existingFetcher ? existingFetcher.data : undefined
4018
4023
  };
4019
4024
  return fetcher;
4020
4025
  }
@@ -4027,12 +4032,11 @@ function getDoneFetcher(data) {
4027
4032
  formData: undefined,
4028
4033
  json: undefined,
4029
4034
  text: undefined,
4030
- data,
4031
- " _hasFetcherDoneAnything ": true
4035
+ data
4032
4036
  };
4033
4037
  return fetcher;
4034
4038
  }
4035
4039
  //#endregion
4036
4040
 
4037
- export { AbortedDeferredError, Action, ErrorResponse, IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION, UNSAFE_DEFERRED_SYMBOL, DeferredData as UNSAFE_DeferredData, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, invariant as UNSAFE_invariant, warning as UNSAFE_warning, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, createRouter, createStaticHandler, defer, generatePath, getStaticContextFromError, getToPathname, isDeferredData, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, parsePath, redirect, redirectDocument, resolvePath, resolveTo, stripBasename };
4041
+ export { AbortedDeferredError, Action, IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION, UNSAFE_DEFERRED_SYMBOL, DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, invariant as UNSAFE_invariant, warning as UNSAFE_warning, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, createRouter, createStaticHandler, defer, generatePath, getStaticContextFromError, getToPathname, isDeferredData, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, parsePath, redirect, redirectDocument, resolvePath, resolveTo, stripBasename };
4038
4042
  //# sourceMappingURL=router.js.map