@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 +13 -0
- package/dist/router.cjs.js +60 -33
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +60 -33
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +60 -33
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/router.ts +52 -23
package/package.json
CHANGED
package/router.ts
CHANGED
|
@@ -735,17 +735,15 @@ export function createRouter(init: RouterInit): Router {
|
|
|
735
735
|
): void {
|
|
736
736
|
// Deduce if we're in a loading/actionReload state:
|
|
737
737
|
// - We have committed actionData in the store
|
|
738
|
-
// - The current navigation was a submission
|
|
738
|
+
// - The current navigation was a mutation submission
|
|
739
739
|
// - We're past the submitting state and into the loading state
|
|
740
|
-
// - The location
|
|
741
|
-
// location, indicating we redirected from the action (avoids false
|
|
742
|
-
// positives for loading/submissionRedirect when actionData returned
|
|
743
|
-
// on a prior submission)
|
|
740
|
+
// - The location being loaded is not the result of a redirect
|
|
744
741
|
let isActionReload =
|
|
745
742
|
state.actionData != null &&
|
|
746
743
|
state.navigation.formMethod != null &&
|
|
744
|
+
isMutationMethod(state.navigation.formMethod) &&
|
|
747
745
|
state.navigation.state === "loading" &&
|
|
748
|
-
state
|
|
746
|
+
location.state?._isRedirect !== true;
|
|
749
747
|
|
|
750
748
|
let actionData: RouteData | null;
|
|
751
749
|
if (newState.actionData) {
|
|
@@ -1092,7 +1090,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1092
1090
|
replace =
|
|
1093
1091
|
result.location === state.location.pathname + state.location.search;
|
|
1094
1092
|
}
|
|
1095
|
-
await startRedirectNavigation(state, result, replace);
|
|
1093
|
+
await startRedirectNavigation(state, result, { submission, replace });
|
|
1096
1094
|
return { shortCircuited: true };
|
|
1097
1095
|
}
|
|
1098
1096
|
|
|
@@ -1152,10 +1150,26 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1152
1150
|
loadingNavigation = navigation;
|
|
1153
1151
|
}
|
|
1154
1152
|
|
|
1153
|
+
// If this was a redirect from an action we don't have a "submission" but
|
|
1154
|
+
// we have it on the loading navigation so use that if available
|
|
1155
|
+
let activeSubmission = submission
|
|
1156
|
+
? submission
|
|
1157
|
+
: loadingNavigation.formMethod &&
|
|
1158
|
+
loadingNavigation.formAction &&
|
|
1159
|
+
loadingNavigation.formData &&
|
|
1160
|
+
loadingNavigation.formEncType
|
|
1161
|
+
? {
|
|
1162
|
+
formMethod: loadingNavigation.formMethod,
|
|
1163
|
+
formAction: loadingNavigation.formAction,
|
|
1164
|
+
formData: loadingNavigation.formData,
|
|
1165
|
+
formEncType: loadingNavigation.formEncType,
|
|
1166
|
+
}
|
|
1167
|
+
: undefined;
|
|
1168
|
+
|
|
1155
1169
|
let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(
|
|
1156
1170
|
state,
|
|
1157
1171
|
matches,
|
|
1158
|
-
|
|
1172
|
+
activeSubmission,
|
|
1159
1173
|
location,
|
|
1160
1174
|
isRevalidationRequired,
|
|
1161
1175
|
cancelledDeferredRoutes,
|
|
@@ -1244,7 +1258,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1244
1258
|
// If any loaders returned a redirect Response, start a new REPLACE navigation
|
|
1245
1259
|
let redirect = findRedirect(results);
|
|
1246
1260
|
if (redirect) {
|
|
1247
|
-
await startRedirectNavigation(state, redirect, replace);
|
|
1261
|
+
await startRedirectNavigation(state, redirect, { replace });
|
|
1248
1262
|
return { shortCircuited: true };
|
|
1249
1263
|
}
|
|
1250
1264
|
|
|
@@ -1401,7 +1415,9 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1401
1415
|
state.fetchers.set(key, loadingFetcher);
|
|
1402
1416
|
updateState({ fetchers: new Map(state.fetchers) });
|
|
1403
1417
|
|
|
1404
|
-
return startRedirectNavigation(state, actionResult,
|
|
1418
|
+
return startRedirectNavigation(state, actionResult, {
|
|
1419
|
+
isFetchActionRedirect: true,
|
|
1420
|
+
});
|
|
1405
1421
|
}
|
|
1406
1422
|
|
|
1407
1423
|
// Process any non-redirect errors thrown
|
|
@@ -1673,8 +1689,15 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1673
1689
|
async function startRedirectNavigation(
|
|
1674
1690
|
state: RouterState,
|
|
1675
1691
|
redirect: RedirectResult,
|
|
1676
|
-
|
|
1677
|
-
|
|
1692
|
+
{
|
|
1693
|
+
submission,
|
|
1694
|
+
replace,
|
|
1695
|
+
isFetchActionRedirect,
|
|
1696
|
+
}: {
|
|
1697
|
+
submission?: Submission;
|
|
1698
|
+
replace?: boolean;
|
|
1699
|
+
isFetchActionRedirect?: boolean;
|
|
1700
|
+
} = {}
|
|
1678
1701
|
) {
|
|
1679
1702
|
if (redirect.revalidate) {
|
|
1680
1703
|
isRevalidationRequired = true;
|
|
@@ -1714,24 +1737,30 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1714
1737
|
let redirectHistoryAction =
|
|
1715
1738
|
replace === true ? HistoryAction.Replace : HistoryAction.Push;
|
|
1716
1739
|
|
|
1740
|
+
// Use the incoming submission if provided, fallback on the active one in
|
|
1741
|
+
// state.navigation
|
|
1717
1742
|
let { formMethod, formAction, formEncType, formData } = state.navigation;
|
|
1743
|
+
if (!submission && formMethod && formAction && formData && formEncType) {
|
|
1744
|
+
submission = {
|
|
1745
|
+
formMethod,
|
|
1746
|
+
formAction,
|
|
1747
|
+
formEncType,
|
|
1748
|
+
formData,
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1718
1751
|
|
|
1719
1752
|
// If this was a 307/308 submission we want to preserve the HTTP method and
|
|
1720
1753
|
// re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the
|
|
1721
1754
|
// redirected location
|
|
1722
1755
|
if (
|
|
1723
1756
|
redirectPreserveMethodStatusCodes.has(redirect.status) &&
|
|
1724
|
-
|
|
1725
|
-
isMutationMethod(formMethod)
|
|
1726
|
-
formEncType &&
|
|
1727
|
-
formData
|
|
1757
|
+
submission &&
|
|
1758
|
+
isMutationMethod(submission.formMethod)
|
|
1728
1759
|
) {
|
|
1729
1760
|
await startNavigation(redirectHistoryAction, redirectLocation, {
|
|
1730
1761
|
submission: {
|
|
1731
|
-
|
|
1762
|
+
...submission,
|
|
1732
1763
|
formAction: redirect.location,
|
|
1733
|
-
formEncType,
|
|
1734
|
-
formData,
|
|
1735
1764
|
},
|
|
1736
1765
|
});
|
|
1737
1766
|
} else {
|
|
@@ -1741,10 +1770,10 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1741
1770
|
overrideNavigation: {
|
|
1742
1771
|
state: "loading",
|
|
1743
1772
|
location: redirectLocation,
|
|
1744
|
-
formMethod: formMethod
|
|
1745
|
-
formAction: formAction
|
|
1746
|
-
formEncType: formEncType
|
|
1747
|
-
formData: formData
|
|
1773
|
+
formMethod: submission ? submission.formMethod : undefined,
|
|
1774
|
+
formAction: submission ? submission.formAction : undefined,
|
|
1775
|
+
formEncType: submission ? submission.formEncType : undefined,
|
|
1776
|
+
formData: submission ? submission.formData : undefined,
|
|
1748
1777
|
},
|
|
1749
1778
|
});
|
|
1750
1779
|
}
|