@remix-run/router 1.2.0 → 1.2.1-pre.1

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.2.0
2
+ * @remix-run/router v1.2.1-pre.1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1548,17 +1548,14 @@
1548
1548
 
1549
1549
 
1550
1550
  function completeNavigation(location, newState) {
1551
- var _state$navigation$for;
1551
+ var _location$state;
1552
1552
 
1553
1553
  // Deduce if we're in a loading/actionReload state:
1554
1554
  // - We have committed actionData in the store
1555
- // - The current navigation was a submission
1555
+ // - The current navigation was a mutation submission
1556
1556
  // - We're past the submitting state and into the loading state
1557
- // - The location we've finished loading is different from the submission
1558
- // location, indicating we redirected from the action (avoids false
1559
- // positives for loading/submissionRedirect when actionData returned
1560
- // on a prior submission)
1561
- let isActionReload = state.actionData != null && state.navigation.formMethod != null && state.navigation.state === "loading" && ((_state$navigation$for = state.navigation.formAction) == null ? void 0 : _state$navigation$for.split("?")[0]) === location.pathname;
1557
+ // - The location being loaded is not the result of a redirect
1558
+ let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && ((_location$state = location.state) == null ? void 0 : _location$state._isRedirect) !== true;
1562
1559
  let actionData;
1563
1560
 
1564
1561
  if (newState.actionData) {
@@ -1841,7 +1838,10 @@
1841
1838
  replace = result.location === state.location.pathname + state.location.search;
1842
1839
  }
1843
1840
 
1844
- await startRedirectNavigation(state, result, replace);
1841
+ await startRedirectNavigation(state, result, {
1842
+ submission,
1843
+ replace
1844
+ });
1845
1845
  return {
1846
1846
  shortCircuited: true
1847
1847
  };
@@ -1896,9 +1896,17 @@
1896
1896
  }, submission);
1897
1897
 
1898
1898
  loadingNavigation = navigation;
1899
- }
1899
+ } // If this was a redirect from an action we don't have a "submission" but
1900
+ // we have it on the loading navigation so use that if available
1901
+
1900
1902
 
1901
- let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(state, matches, submission, location, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, pendingActionData, pendingError, fetchLoadMatches); // Cancel pending deferreds for no-longer-matched routes or routes we're
1903
+ let activeSubmission = submission ? submission : loadingNavigation.formMethod && loadingNavigation.formAction && loadingNavigation.formData && loadingNavigation.formEncType ? {
1904
+ formMethod: loadingNavigation.formMethod,
1905
+ formAction: loadingNavigation.formAction,
1906
+ formData: loadingNavigation.formData,
1907
+ formEncType: loadingNavigation.formEncType
1908
+ } : undefined;
1909
+ let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(state, matches, activeSubmission, location, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, pendingActionData, pendingError, fetchLoadMatches); // Cancel pending deferreds for no-longer-matched routes or routes we're
1902
1910
  // about to reload. Note that if this is an action reload we would have
1903
1911
  // already cancelled all pending deferreds so this would be a no-op
1904
1912
 
@@ -1977,7 +1985,9 @@
1977
1985
  let redirect = findRedirect(results);
1978
1986
 
1979
1987
  if (redirect) {
1980
- await startRedirectNavigation(state, redirect, replace);
1988
+ await startRedirectNavigation(state, redirect, {
1989
+ replace
1990
+ });
1981
1991
  return {
1982
1992
  shortCircuited: true
1983
1993
  };
@@ -2107,7 +2117,9 @@
2107
2117
  updateState({
2108
2118
  fetchers: new Map(state.fetchers)
2109
2119
  });
2110
- return startRedirectNavigation(state, actionResult, false, true);
2120
+ return startRedirectNavigation(state, actionResult, {
2121
+ isFetchActionRedirect: true
2122
+ });
2111
2123
  } // Process any non-redirect errors thrown
2112
2124
 
2113
2125
 
@@ -2330,9 +2342,15 @@
2330
2342
  */
2331
2343
 
2332
2344
 
2333
- async function startRedirectNavigation(state, redirect, replace, isFetchActionRedirect) {
2345
+ async function startRedirectNavigation(state, redirect, _temp) {
2334
2346
  var _window;
2335
2347
 
2348
+ let {
2349
+ submission,
2350
+ replace,
2351
+ isFetchActionRedirect
2352
+ } = _temp === void 0 ? {} : _temp;
2353
+
2336
2354
  if (redirect.revalidate) {
2337
2355
  isRevalidationRequired = true;
2338
2356
  }
@@ -2362,24 +2380,33 @@
2362
2380
 
2363
2381
 
2364
2382
  pendingNavigationController = null;
2365
- let redirectHistoryAction = replace === true ? exports.Action.Replace : exports.Action.Push;
2383
+ let redirectHistoryAction = replace === true ? exports.Action.Replace : exports.Action.Push; // Use the incoming submission if provided, fallback on the active one in
2384
+ // state.navigation
2385
+
2366
2386
  let {
2367
2387
  formMethod,
2368
2388
  formAction,
2369
2389
  formEncType,
2370
2390
  formData
2371
- } = state.navigation; // If this was a 307/308 submission we want to preserve the HTTP method and
2391
+ } = state.navigation;
2392
+
2393
+ if (!submission && formMethod && formAction && formData && formEncType) {
2394
+ submission = {
2395
+ formMethod,
2396
+ formAction,
2397
+ formEncType,
2398
+ formData
2399
+ };
2400
+ } // If this was a 307/308 submission we want to preserve the HTTP method and
2372
2401
  // re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the
2373
2402
  // redirected location
2374
2403
 
2375
- if (redirectPreserveMethodStatusCodes.has(redirect.status) && formMethod && isMutationMethod(formMethod) && formEncType && formData) {
2404
+
2405
+ if (redirectPreserveMethodStatusCodes.has(redirect.status) && submission && isMutationMethod(submission.formMethod)) {
2376
2406
  await startNavigation(redirectHistoryAction, redirectLocation, {
2377
- submission: {
2378
- formMethod,
2379
- formAction: redirect.location,
2380
- formEncType,
2381
- formData
2382
- }
2407
+ submission: _extends({}, submission, {
2408
+ formAction: redirect.location
2409
+ })
2383
2410
  });
2384
2411
  } else {
2385
2412
  // Otherwise, we kick off a new loading navigation, preserving the
@@ -2388,10 +2415,10 @@
2388
2415
  overrideNavigation: {
2389
2416
  state: "loading",
2390
2417
  location: redirectLocation,
2391
- formMethod: formMethod || undefined,
2392
- formAction: formAction || undefined,
2393
- formEncType: formEncType || undefined,
2394
- formData: formData || undefined
2418
+ formMethod: submission ? submission.formMethod : undefined,
2419
+ formAction: submission ? submission.formAction : undefined,
2420
+ formEncType: submission ? submission.formEncType : undefined,
2421
+ formData: submission ? submission.formData : undefined
2395
2422
  }
2396
2423
  });
2397
2424
  }
@@ -2636,10 +2663,10 @@
2636
2663
  * return it directly.
2637
2664
  */
2638
2665
 
2639
- async function query(request, _temp) {
2666
+ async function query(request, _temp2) {
2640
2667
  let {
2641
2668
  requestContext
2642
- } = _temp === void 0 ? {} : _temp;
2669
+ } = _temp2 === void 0 ? {} : _temp2;
2643
2670
  let url = new URL(request.url);
2644
2671
  let method = request.method.toLowerCase();
2645
2672
  let location = createLocation("", createPath(url), null, "default");
@@ -2725,11 +2752,11 @@
2725
2752
  */
2726
2753
 
2727
2754
 
2728
- async function queryRoute(request, _temp2) {
2755
+ async function queryRoute(request, _temp3) {
2729
2756
  let {
2730
2757
  routeId,
2731
2758
  requestContext
2732
- } = _temp2 === void 0 ? {} : _temp2;
2759
+ } = _temp3 === void 0 ? {} : _temp3;
2733
2760
  let url = new URL(request.url);
2734
2761
  let method = request.method.toLowerCase();
2735
2762
  let location = createLocation("", createPath(url), null, "default");
@@ -3510,12 +3537,12 @@
3510
3537
  };
3511
3538
  }
3512
3539
 
3513
- function getInternalRouterError(status, _temp3) {
3540
+ function getInternalRouterError(status, _temp4) {
3514
3541
  let {
3515
3542
  pathname,
3516
3543
  routeId,
3517
3544
  method
3518
- } = _temp3 === void 0 ? {} : _temp3;
3545
+ } = _temp4 === void 0 ? {} : _temp4;
3519
3546
  let statusText = "Unknown Server Error";
3520
3547
  let errorMessage = "Unknown @remix-run/router error";
3521
3548