@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.2.1-pre.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Reset `actionData` on action redirect to current location ([#9772](https://github.com/remix-run/react-router/pull/9772))
8
+ - Fix fetcher shouldRevalidate ([#9782](https://github.com/remix-run/react-router/pull/9782))
9
+
10
+ ## 1.2.1-pre.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Include submission info in `shouldRevalidate` on action redirects ([#9777](https://github.com/remix-run/react-router/pull/9777))
15
+
3
16
  ## 1.2.0
4
17
 
5
18
  ### Minor Changes
@@ -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
  *
@@ -1546,17 +1546,14 @@ function createRouter(init) {
1546
1546
 
1547
1547
 
1548
1548
  function completeNavigation(location, newState) {
1549
- var _state$navigation$for;
1549
+ var _location$state;
1550
1550
 
1551
1551
  // Deduce if we're in a loading/actionReload state:
1552
1552
  // - We have committed actionData in the store
1553
- // - The current navigation was a submission
1553
+ // - The current navigation was a mutation submission
1554
1554
  // - We're past the submitting state and into the loading state
1555
- // - The location we've finished loading is different from the submission
1556
- // location, indicating we redirected from the action (avoids false
1557
- // positives for loading/submissionRedirect when actionData returned
1558
- // on a prior submission)
1559
- 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;
1555
+ // - The location being loaded is not the result of a redirect
1556
+ 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;
1560
1557
  let actionData;
1561
1558
 
1562
1559
  if (newState.actionData) {
@@ -1839,7 +1836,10 @@ function createRouter(init) {
1839
1836
  replace = result.location === state.location.pathname + state.location.search;
1840
1837
  }
1841
1838
 
1842
- await startRedirectNavigation(state, result, replace);
1839
+ await startRedirectNavigation(state, result, {
1840
+ submission,
1841
+ replace
1842
+ });
1843
1843
  return {
1844
1844
  shortCircuited: true
1845
1845
  };
@@ -1894,9 +1894,17 @@ function createRouter(init) {
1894
1894
  }, submission);
1895
1895
 
1896
1896
  loadingNavigation = navigation;
1897
- }
1897
+ } // If this was a redirect from an action we don't have a "submission" but
1898
+ // we have it on the loading navigation so use that if available
1899
+
1898
1900
 
1899
- 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
1901
+ let activeSubmission = submission ? submission : loadingNavigation.formMethod && loadingNavigation.formAction && loadingNavigation.formData && loadingNavigation.formEncType ? {
1902
+ formMethod: loadingNavigation.formMethod,
1903
+ formAction: loadingNavigation.formAction,
1904
+ formData: loadingNavigation.formData,
1905
+ formEncType: loadingNavigation.formEncType
1906
+ } : undefined;
1907
+ 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
1900
1908
  // about to reload. Note that if this is an action reload we would have
1901
1909
  // already cancelled all pending deferreds so this would be a no-op
1902
1910
 
@@ -1975,7 +1983,9 @@ function createRouter(init) {
1975
1983
  let redirect = findRedirect(results);
1976
1984
 
1977
1985
  if (redirect) {
1978
- await startRedirectNavigation(state, redirect, replace);
1986
+ await startRedirectNavigation(state, redirect, {
1987
+ replace
1988
+ });
1979
1989
  return {
1980
1990
  shortCircuited: true
1981
1991
  };
@@ -2105,7 +2115,9 @@ function createRouter(init) {
2105
2115
  updateState({
2106
2116
  fetchers: new Map(state.fetchers)
2107
2117
  });
2108
- return startRedirectNavigation(state, actionResult, false, true);
2118
+ return startRedirectNavigation(state, actionResult, {
2119
+ isFetchActionRedirect: true
2120
+ });
2109
2121
  } // Process any non-redirect errors thrown
2110
2122
 
2111
2123
 
@@ -2328,9 +2340,15 @@ function createRouter(init) {
2328
2340
  */
2329
2341
 
2330
2342
 
2331
- async function startRedirectNavigation(state, redirect, replace, isFetchActionRedirect) {
2343
+ async function startRedirectNavigation(state, redirect, _temp) {
2332
2344
  var _window;
2333
2345
 
2346
+ let {
2347
+ submission,
2348
+ replace,
2349
+ isFetchActionRedirect
2350
+ } = _temp === void 0 ? {} : _temp;
2351
+
2334
2352
  if (redirect.revalidate) {
2335
2353
  isRevalidationRequired = true;
2336
2354
  }
@@ -2360,24 +2378,33 @@ function createRouter(init) {
2360
2378
 
2361
2379
 
2362
2380
  pendingNavigationController = null;
2363
- let redirectHistoryAction = replace === true ? exports.Action.Replace : exports.Action.Push;
2381
+ let redirectHistoryAction = replace === true ? exports.Action.Replace : exports.Action.Push; // Use the incoming submission if provided, fallback on the active one in
2382
+ // state.navigation
2383
+
2364
2384
  let {
2365
2385
  formMethod,
2366
2386
  formAction,
2367
2387
  formEncType,
2368
2388
  formData
2369
- } = state.navigation; // If this was a 307/308 submission we want to preserve the HTTP method and
2389
+ } = state.navigation;
2390
+
2391
+ if (!submission && formMethod && formAction && formData && formEncType) {
2392
+ submission = {
2393
+ formMethod,
2394
+ formAction,
2395
+ formEncType,
2396
+ formData
2397
+ };
2398
+ } // If this was a 307/308 submission we want to preserve the HTTP method and
2370
2399
  // re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the
2371
2400
  // redirected location
2372
2401
 
2373
- if (redirectPreserveMethodStatusCodes.has(redirect.status) && formMethod && isMutationMethod(formMethod) && formEncType && formData) {
2402
+
2403
+ if (redirectPreserveMethodStatusCodes.has(redirect.status) && submission && isMutationMethod(submission.formMethod)) {
2374
2404
  await startNavigation(redirectHistoryAction, redirectLocation, {
2375
- submission: {
2376
- formMethod,
2377
- formAction: redirect.location,
2378
- formEncType,
2379
- formData
2380
- }
2405
+ submission: _extends({}, submission, {
2406
+ formAction: redirect.location
2407
+ })
2381
2408
  });
2382
2409
  } else {
2383
2410
  // Otherwise, we kick off a new loading navigation, preserving the
@@ -2386,10 +2413,10 @@ function createRouter(init) {
2386
2413
  overrideNavigation: {
2387
2414
  state: "loading",
2388
2415
  location: redirectLocation,
2389
- formMethod: formMethod || undefined,
2390
- formAction: formAction || undefined,
2391
- formEncType: formEncType || undefined,
2392
- formData: formData || undefined
2416
+ formMethod: submission ? submission.formMethod : undefined,
2417
+ formAction: submission ? submission.formAction : undefined,
2418
+ formEncType: submission ? submission.formEncType : undefined,
2419
+ formData: submission ? submission.formData : undefined
2393
2420
  }
2394
2421
  });
2395
2422
  }
@@ -2634,10 +2661,10 @@ function createStaticHandler(routes, opts) {
2634
2661
  * return it directly.
2635
2662
  */
2636
2663
 
2637
- async function query(request, _temp) {
2664
+ async function query(request, _temp2) {
2638
2665
  let {
2639
2666
  requestContext
2640
- } = _temp === void 0 ? {} : _temp;
2667
+ } = _temp2 === void 0 ? {} : _temp2;
2641
2668
  let url = new URL(request.url);
2642
2669
  let method = request.method.toLowerCase();
2643
2670
  let location = createLocation("", createPath(url), null, "default");
@@ -2723,11 +2750,11 @@ function createStaticHandler(routes, opts) {
2723
2750
  */
2724
2751
 
2725
2752
 
2726
- async function queryRoute(request, _temp2) {
2753
+ async function queryRoute(request, _temp3) {
2727
2754
  let {
2728
2755
  routeId,
2729
2756
  requestContext
2730
- } = _temp2 === void 0 ? {} : _temp2;
2757
+ } = _temp3 === void 0 ? {} : _temp3;
2731
2758
  let url = new URL(request.url);
2732
2759
  let method = request.method.toLowerCase();
2733
2760
  let location = createLocation("", createPath(url), null, "default");
@@ -3508,12 +3535,12 @@ function getShortCircuitMatches(routes) {
3508
3535
  };
3509
3536
  }
3510
3537
 
3511
- function getInternalRouterError(status, _temp3) {
3538
+ function getInternalRouterError(status, _temp4) {
3512
3539
  let {
3513
3540
  pathname,
3514
3541
  routeId,
3515
3542
  method
3516
- } = _temp3 === void 0 ? {} : _temp3;
3543
+ } = _temp4 === void 0 ? {} : _temp4;
3517
3544
  let statusText = "Unknown Server Error";
3518
3545
  let errorMessage = "Unknown @remix-run/router error";
3519
3546