@remix-run/router 0.0.0-experimental-a077dc2d → 0.0.0-experimental-e192105b
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 +22 -0
- package/dist/router.cjs.js +135 -65
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +3 -0
- package/dist/router.js +131 -65
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +135 -65
- 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 +184 -93
package/package.json
CHANGED
package/router.ts
CHANGED
|
@@ -409,7 +409,9 @@ export interface RouterSubscriber {
|
|
|
409
409
|
(
|
|
410
410
|
state: RouterState,
|
|
411
411
|
opts: {
|
|
412
|
+
deletedFetchers: string[];
|
|
412
413
|
unstable_viewTransitionOpts?: ViewTransitionOpts;
|
|
414
|
+
unstable_flushSync?: boolean;
|
|
413
415
|
}
|
|
414
416
|
): void;
|
|
415
417
|
}
|
|
@@ -435,6 +437,7 @@ export type RelativeRoutingType = "route" | "path";
|
|
|
435
437
|
type BaseNavigateOrFetchOptions = {
|
|
436
438
|
preventScrollReset?: boolean;
|
|
437
439
|
relative?: RelativeRoutingType;
|
|
440
|
+
unstable_flushSync?: boolean;
|
|
438
441
|
};
|
|
439
442
|
|
|
440
443
|
// Only allowed for navigations
|
|
@@ -840,6 +843,9 @@ export function createRouter(init: RouterInit): Router {
|
|
|
840
843
|
// Should the current navigation enable document.startViewTransition?
|
|
841
844
|
let pendingViewTransitionEnabled = false;
|
|
842
845
|
|
|
846
|
+
// Should the current navigation use flushSync for state updates?
|
|
847
|
+
let pendingFlushSync = false;
|
|
848
|
+
|
|
843
849
|
// Store applied view transitions so we can apply them on POP
|
|
844
850
|
let appliedViewTransitions: Map<string, Set<string>> = new Map<
|
|
845
851
|
string,
|
|
@@ -887,6 +893,9 @@ export function createRouter(init: RouterInit): Router {
|
|
|
887
893
|
// Most recent href/match for fetcher.load calls for fetchers
|
|
888
894
|
let fetchLoadMatches = new Map<string, FetchLoadMatch>();
|
|
889
895
|
|
|
896
|
+
// Ref-count mounted fetchers so we know when it's ok to clean them up
|
|
897
|
+
let activeFetchers = new Map<string, number>();
|
|
898
|
+
|
|
890
899
|
// Fetchers that have requested a delete when using v7_fetcherPersist,
|
|
891
900
|
// they'll be officially removed after they return to idle
|
|
892
901
|
let deletedFetchers = new Set<string>();
|
|
@@ -958,7 +967,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
958
967
|
reset() {
|
|
959
968
|
let blockers = new Map(state.blockers);
|
|
960
969
|
blockers.set(blockerKey!, IDLE_BLOCKER);
|
|
961
|
-
updateState({ blockers });
|
|
970
|
+
updateState({ blockers }, { flushSync: false });
|
|
962
971
|
},
|
|
963
972
|
});
|
|
964
973
|
return;
|
|
@@ -1014,33 +1023,52 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1014
1023
|
// Update our state and notify the calling context of the change
|
|
1015
1024
|
function updateState(
|
|
1016
1025
|
newState: Partial<RouterState>,
|
|
1017
|
-
|
|
1026
|
+
opts: {
|
|
1027
|
+
flushSync: boolean;
|
|
1028
|
+
viewTransitionOpts?: ViewTransitionOpts;
|
|
1029
|
+
}
|
|
1018
1030
|
): void {
|
|
1019
1031
|
state = {
|
|
1020
1032
|
...state,
|
|
1021
1033
|
...newState,
|
|
1022
1034
|
};
|
|
1023
|
-
subscribers.forEach((subscriber) =>
|
|
1024
|
-
subscriber(state, { unstable_viewTransitionOpts: viewTransitionOpts })
|
|
1025
|
-
);
|
|
1026
1035
|
|
|
1027
|
-
//
|
|
1036
|
+
// Prep fetcher cleanup so we can tell the UI which fetcher data entries
|
|
1037
|
+
// can be removed
|
|
1038
|
+
let completedFetchers: string[] = [];
|
|
1039
|
+
let deletedFetchersKeys: string[] = [];
|
|
1040
|
+
|
|
1028
1041
|
if (future.v7_fetcherPersist) {
|
|
1029
1042
|
state.fetchers.forEach((fetcher, key) => {
|
|
1030
1043
|
if (fetcher.state === "idle") {
|
|
1031
1044
|
if (deletedFetchers.has(key)) {
|
|
1032
|
-
//
|
|
1033
|
-
|
|
1034
|
-
deleteFetcher(key);
|
|
1045
|
+
// Unmounted from the UI and can be totally removed
|
|
1046
|
+
deletedFetchersKeys.push(key);
|
|
1035
1047
|
} else {
|
|
1036
|
-
//
|
|
1037
|
-
//
|
|
1038
|
-
|
|
1039
|
-
state.fetchers.delete(key);
|
|
1048
|
+
// Returned to idle but still mounted in the UI, so semi-remains for
|
|
1049
|
+
// revalidations and such
|
|
1050
|
+
completedFetchers.push(key);
|
|
1040
1051
|
}
|
|
1041
1052
|
}
|
|
1042
1053
|
});
|
|
1043
1054
|
}
|
|
1055
|
+
|
|
1056
|
+
// Iterate over a local copy so that if flushSync is used and we end up
|
|
1057
|
+
// removing and adding a new subscriber due to the useCallback dependencies,
|
|
1058
|
+
// we don't get ourselves into a loop calling the new subscriber immediately
|
|
1059
|
+
[...subscribers].forEach((subscriber) =>
|
|
1060
|
+
subscriber(state, {
|
|
1061
|
+
deletedFetchers: deletedFetchersKeys,
|
|
1062
|
+
unstable_viewTransitionOpts: opts.viewTransitionOpts,
|
|
1063
|
+
unstable_flushSync: opts.flushSync,
|
|
1064
|
+
})
|
|
1065
|
+
);
|
|
1066
|
+
|
|
1067
|
+
// Remove idle fetchers from state since we only care about in-flight fetchers.
|
|
1068
|
+
if (future.v7_fetcherPersist) {
|
|
1069
|
+
completedFetchers.forEach((key) => state.fetchers.delete(key));
|
|
1070
|
+
deletedFetchersKeys.forEach((key) => deleteFetcher(key));
|
|
1071
|
+
}
|
|
1044
1072
|
}
|
|
1045
1073
|
|
|
1046
1074
|
// Complete a navigation returning the state.navigation back to the IDLE_NAVIGATION
|
|
@@ -1172,13 +1200,17 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1172
1200
|
preventScrollReset,
|
|
1173
1201
|
blockers,
|
|
1174
1202
|
},
|
|
1175
|
-
|
|
1203
|
+
{
|
|
1204
|
+
viewTransitionOpts,
|
|
1205
|
+
flushSync: pendingFlushSync,
|
|
1206
|
+
}
|
|
1176
1207
|
);
|
|
1177
1208
|
|
|
1178
1209
|
// Reset stateful navigation vars
|
|
1179
1210
|
pendingAction = HistoryAction.Pop;
|
|
1180
1211
|
pendingPreventScrollReset = false;
|
|
1181
1212
|
pendingViewTransitionEnabled = false;
|
|
1213
|
+
pendingFlushSync = false;
|
|
1182
1214
|
isUninterruptedRevalidation = false;
|
|
1183
1215
|
isRevalidationRequired = false;
|
|
1184
1216
|
cancelledDeferredRoutes = [];
|
|
@@ -1250,6 +1282,8 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1250
1282
|
? opts.preventScrollReset === true
|
|
1251
1283
|
: undefined;
|
|
1252
1284
|
|
|
1285
|
+
let flushSync = (opts && opts.unstable_flushSync) === true;
|
|
1286
|
+
|
|
1253
1287
|
let blockerKey = shouldBlockNavigation({
|
|
1254
1288
|
currentLocation,
|
|
1255
1289
|
nextLocation,
|
|
@@ -1274,7 +1308,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1274
1308
|
reset() {
|
|
1275
1309
|
let blockers = new Map(state.blockers);
|
|
1276
1310
|
blockers.set(blockerKey!, IDLE_BLOCKER);
|
|
1277
|
-
updateState({ blockers });
|
|
1311
|
+
updateState({ blockers }, { flushSync });
|
|
1278
1312
|
},
|
|
1279
1313
|
});
|
|
1280
1314
|
return;
|
|
@@ -1288,6 +1322,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1288
1322
|
preventScrollReset,
|
|
1289
1323
|
replace: opts && opts.replace,
|
|
1290
1324
|
enableViewTransition: opts && opts.unstable_viewTransition,
|
|
1325
|
+
flushSync,
|
|
1291
1326
|
});
|
|
1292
1327
|
}
|
|
1293
1328
|
|
|
@@ -1296,7 +1331,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1296
1331
|
// loaders during the next loader round
|
|
1297
1332
|
function revalidate() {
|
|
1298
1333
|
interruptActiveLoads();
|
|
1299
|
-
updateState({ revalidation: "loading" });
|
|
1334
|
+
updateState({ revalidation: "loading" }, { flushSync: false });
|
|
1300
1335
|
|
|
1301
1336
|
// If we're currently submitting an action, we don't need to start a new
|
|
1302
1337
|
// navigation, we'll just let the follow up loader execution call all loaders
|
|
@@ -1339,6 +1374,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1339
1374
|
preventScrollReset?: boolean;
|
|
1340
1375
|
replace?: boolean;
|
|
1341
1376
|
enableViewTransition?: boolean;
|
|
1377
|
+
flushSync?: boolean;
|
|
1342
1378
|
}
|
|
1343
1379
|
): Promise<void> {
|
|
1344
1380
|
// Abort any in-progress navigations and start a new one. Unset any ongoing
|
|
@@ -1356,6 +1392,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1356
1392
|
pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1357
1393
|
|
|
1358
1394
|
pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
|
|
1395
|
+
pendingFlushSync = (opts && opts.flushSync) === true;
|
|
1359
1396
|
|
|
1360
1397
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1361
1398
|
let loadingNavigation = opts && opts.overrideNavigation;
|
|
@@ -1482,7 +1519,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1482
1519
|
|
|
1483
1520
|
// Put us in a submitting state
|
|
1484
1521
|
let navigation = getSubmittingNavigation(location, submission);
|
|
1485
|
-
updateState({ navigation });
|
|
1522
|
+
updateState({ navigation }, { flushSync: pendingFlushSync });
|
|
1486
1523
|
|
|
1487
1524
|
// Call our action and get the result
|
|
1488
1525
|
let result: DataResult;
|
|
@@ -1638,17 +1675,22 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1638
1675
|
state.fetchers.set(rf.key, revalidatingFetcher);
|
|
1639
1676
|
});
|
|
1640
1677
|
let actionData = pendingActionData || state.actionData;
|
|
1641
|
-
updateState(
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
?
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1678
|
+
updateState(
|
|
1679
|
+
{
|
|
1680
|
+
navigation: loadingNavigation,
|
|
1681
|
+
...(actionData
|
|
1682
|
+
? Object.keys(actionData).length === 0
|
|
1683
|
+
? { actionData: null }
|
|
1684
|
+
: { actionData }
|
|
1685
|
+
: {}),
|
|
1686
|
+
...(revalidatingFetchers.length > 0
|
|
1687
|
+
? { fetchers: new Map(state.fetchers) }
|
|
1688
|
+
: {}),
|
|
1689
|
+
},
|
|
1690
|
+
{
|
|
1691
|
+
flushSync: pendingFlushSync,
|
|
1692
|
+
}
|
|
1693
|
+
);
|
|
1652
1694
|
}
|
|
1653
1695
|
|
|
1654
1696
|
revalidatingFetchers.forEach((rf) => {
|
|
@@ -1748,10 +1790,6 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1748
1790
|
};
|
|
1749
1791
|
}
|
|
1750
1792
|
|
|
1751
|
-
function getFetcher<TData = any>(key: string): Fetcher<TData> {
|
|
1752
|
-
return state.fetchers.get(key) || IDLE_FETCHER;
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
1793
|
// Trigger a fetcher load/submit for the given fetcher key
|
|
1756
1794
|
function fetch(
|
|
1757
1795
|
key: string,
|
|
@@ -1768,6 +1806,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1768
1806
|
}
|
|
1769
1807
|
|
|
1770
1808
|
if (fetchControllers.has(key)) abortFetcher(key);
|
|
1809
|
+
let flushSync = (opts && opts.unstable_flushSync) === true;
|
|
1771
1810
|
|
|
1772
1811
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1773
1812
|
let normalizedPath = normalizeTo(
|
|
@@ -1785,7 +1824,8 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1785
1824
|
setFetcherError(
|
|
1786
1825
|
key,
|
|
1787
1826
|
routeId,
|
|
1788
|
-
getInternalRouterError(404, { pathname: normalizedPath })
|
|
1827
|
+
getInternalRouterError(404, { pathname: normalizedPath }),
|
|
1828
|
+
{ flushSync }
|
|
1789
1829
|
);
|
|
1790
1830
|
return;
|
|
1791
1831
|
}
|
|
@@ -1798,7 +1838,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1798
1838
|
);
|
|
1799
1839
|
|
|
1800
1840
|
if (error) {
|
|
1801
|
-
setFetcherError(key, routeId, error);
|
|
1841
|
+
setFetcherError(key, routeId, error, { flushSync });
|
|
1802
1842
|
return;
|
|
1803
1843
|
}
|
|
1804
1844
|
|
|
@@ -1807,14 +1847,30 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1807
1847
|
pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
1808
1848
|
|
|
1809
1849
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
1810
|
-
handleFetcherAction(
|
|
1850
|
+
handleFetcherAction(
|
|
1851
|
+
key,
|
|
1852
|
+
routeId,
|
|
1853
|
+
path,
|
|
1854
|
+
match,
|
|
1855
|
+
matches,
|
|
1856
|
+
flushSync,
|
|
1857
|
+
submission
|
|
1858
|
+
);
|
|
1811
1859
|
return;
|
|
1812
1860
|
}
|
|
1813
1861
|
|
|
1814
1862
|
// Store off the match so we can call it's shouldRevalidate on subsequent
|
|
1815
1863
|
// revalidations
|
|
1816
1864
|
fetchLoadMatches.set(key, { routeId, path });
|
|
1817
|
-
handleFetcherLoader(
|
|
1865
|
+
handleFetcherLoader(
|
|
1866
|
+
key,
|
|
1867
|
+
routeId,
|
|
1868
|
+
path,
|
|
1869
|
+
match,
|
|
1870
|
+
matches,
|
|
1871
|
+
flushSync,
|
|
1872
|
+
submission
|
|
1873
|
+
);
|
|
1818
1874
|
}
|
|
1819
1875
|
|
|
1820
1876
|
// Call the action for the matched fetcher.submit(), and then handle redirects,
|
|
@@ -1825,6 +1881,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1825
1881
|
path: string,
|
|
1826
1882
|
match: AgnosticDataRouteMatch,
|
|
1827
1883
|
requestMatches: AgnosticDataRouteMatch[],
|
|
1884
|
+
flushSync: boolean,
|
|
1828
1885
|
submission: Submission
|
|
1829
1886
|
) {
|
|
1830
1887
|
interruptActiveLoads();
|
|
@@ -1836,15 +1893,15 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1836
1893
|
pathname: path,
|
|
1837
1894
|
routeId: routeId,
|
|
1838
1895
|
});
|
|
1839
|
-
setFetcherError(key, routeId, error);
|
|
1896
|
+
setFetcherError(key, routeId, error, { flushSync });
|
|
1840
1897
|
return;
|
|
1841
1898
|
}
|
|
1842
1899
|
|
|
1843
1900
|
// Put this fetcher into it's submitting state
|
|
1844
1901
|
let existingFetcher = state.fetchers.get(key);
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1902
|
+
updateFetcherState(key, getSubmittingFetcher(submission, existingFetcher), {
|
|
1903
|
+
flushSync,
|
|
1904
|
+
});
|
|
1848
1905
|
|
|
1849
1906
|
// Call the action for the fetcher
|
|
1850
1907
|
let abortController = new AbortController();
|
|
@@ -1868,7 +1925,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1868
1925
|
);
|
|
1869
1926
|
|
|
1870
1927
|
if (fetchRequest.signal.aborted) {
|
|
1871
|
-
// We can delete this so long as we weren't aborted by
|
|
1928
|
+
// We can delete this so long as we weren't aborted by our own fetcher
|
|
1872
1929
|
// re-submit which would have put _new_ controller is in fetchControllers
|
|
1873
1930
|
if (fetchControllers.get(key) === abortController) {
|
|
1874
1931
|
fetchControllers.delete(key);
|
|
@@ -1876,6 +1933,11 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1876
1933
|
return;
|
|
1877
1934
|
}
|
|
1878
1935
|
|
|
1936
|
+
if (deletedFetchers.has(key)) {
|
|
1937
|
+
updateFetcherState(key, getDoneFetcher(undefined), { flushSync });
|
|
1938
|
+
return;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1879
1941
|
if (isRedirectResult(actionResult)) {
|
|
1880
1942
|
fetchControllers.delete(key);
|
|
1881
1943
|
if (pendingNavigationLoadId > originatingLoadId) {
|
|
@@ -1883,16 +1945,11 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1883
1945
|
// should take precedence over this redirect navigation. We already
|
|
1884
1946
|
// set isRevalidationRequired so all loaders for the new route should
|
|
1885
1947
|
// fire unless opted out via shouldRevalidate
|
|
1886
|
-
|
|
1887
|
-
state.fetchers.set(key, doneFetcher);
|
|
1888
|
-
updateState({ fetchers: new Map(state.fetchers) });
|
|
1948
|
+
updateFetcherState(key, getDoneFetcher(undefined), { flushSync });
|
|
1889
1949
|
return;
|
|
1890
1950
|
} else {
|
|
1891
1951
|
fetchRedirectIds.add(key);
|
|
1892
|
-
|
|
1893
|
-
state.fetchers.set(key, loadingFetcher);
|
|
1894
|
-
updateState({ fetchers: new Map(state.fetchers) });
|
|
1895
|
-
|
|
1952
|
+
updateFetcherState(key, getLoadingFetcher(submission), { flushSync });
|
|
1896
1953
|
return startRedirectNavigation(state, actionResult, {
|
|
1897
1954
|
fetcherSubmission: submission,
|
|
1898
1955
|
});
|
|
@@ -1901,7 +1958,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1901
1958
|
|
|
1902
1959
|
// Process any non-redirect errors thrown
|
|
1903
1960
|
if (isErrorResult(actionResult)) {
|
|
1904
|
-
setFetcherError(key, routeId, actionResult.error);
|
|
1961
|
+
setFetcherError(key, routeId, actionResult.error, { flushSync });
|
|
1905
1962
|
return;
|
|
1906
1963
|
}
|
|
1907
1964
|
|
|
@@ -1969,7 +2026,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1969
2026
|
}
|
|
1970
2027
|
});
|
|
1971
2028
|
|
|
1972
|
-
updateState({ fetchers: new Map(state.fetchers) });
|
|
2029
|
+
updateState({ fetchers: new Map(state.fetchers) }, { flushSync });
|
|
1973
2030
|
|
|
1974
2031
|
let abortPendingFetchRevalidations = () =>
|
|
1975
2032
|
revalidatingFetchers.forEach((rf) => abortFetcher(rf.key));
|
|
@@ -2055,16 +2112,19 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2055
2112
|
// otherwise just update with the fetcher data, preserving any existing
|
|
2056
2113
|
// loaderData for loaders that did not need to reload. We have to
|
|
2057
2114
|
// manually merge here since we aren't going through completeNavigation
|
|
2058
|
-
updateState(
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2115
|
+
updateState(
|
|
2116
|
+
{
|
|
2117
|
+
errors,
|
|
2118
|
+
loaderData: mergeLoaderData(
|
|
2119
|
+
state.loaderData,
|
|
2120
|
+
loaderData,
|
|
2121
|
+
matches,
|
|
2122
|
+
errors
|
|
2123
|
+
),
|
|
2124
|
+
fetchers: new Map(state.fetchers),
|
|
2125
|
+
},
|
|
2126
|
+
{ flushSync }
|
|
2127
|
+
);
|
|
2068
2128
|
isRevalidationRequired = false;
|
|
2069
2129
|
}
|
|
2070
2130
|
}
|
|
@@ -2076,16 +2136,18 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2076
2136
|
path: string,
|
|
2077
2137
|
match: AgnosticDataRouteMatch,
|
|
2078
2138
|
matches: AgnosticDataRouteMatch[],
|
|
2139
|
+
flushSync: boolean,
|
|
2079
2140
|
submission?: Submission
|
|
2080
2141
|
) {
|
|
2081
2142
|
let existingFetcher = state.fetchers.get(key);
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2143
|
+
updateFetcherState(
|
|
2144
|
+
key,
|
|
2145
|
+
getLoadingFetcher(
|
|
2146
|
+
submission,
|
|
2147
|
+
existingFetcher ? existingFetcher.data : undefined
|
|
2148
|
+
),
|
|
2149
|
+
{ flushSync }
|
|
2086
2150
|
);
|
|
2087
|
-
state.fetchers.set(key, loadingFetcher);
|
|
2088
|
-
updateState({ fetchers: new Map(state.fetchers) });
|
|
2089
2151
|
|
|
2090
2152
|
// Call the loader for this fetcher route match
|
|
2091
2153
|
let abortController = new AbortController();
|
|
@@ -2127,14 +2189,17 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2127
2189
|
return;
|
|
2128
2190
|
}
|
|
2129
2191
|
|
|
2192
|
+
if (deletedFetchers.has(key)) {
|
|
2193
|
+
updateFetcherState(key, getDoneFetcher(undefined), { flushSync });
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2130
2197
|
// If the loader threw a redirect Response, start a new REPLACE navigation
|
|
2131
2198
|
if (isRedirectResult(result)) {
|
|
2132
2199
|
if (pendingNavigationLoadId > originatingLoadId) {
|
|
2133
2200
|
// A new navigation was kicked off after our loader started, so that
|
|
2134
2201
|
// should take precedence over this redirect navigation
|
|
2135
|
-
|
|
2136
|
-
state.fetchers.set(key, doneFetcher);
|
|
2137
|
-
updateState({ fetchers: new Map(state.fetchers) });
|
|
2202
|
+
updateFetcherState(key, getDoneFetcher(undefined), { flushSync });
|
|
2138
2203
|
return;
|
|
2139
2204
|
} else {
|
|
2140
2205
|
fetchRedirectIds.add(key);
|
|
@@ -2145,26 +2210,14 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2145
2210
|
|
|
2146
2211
|
// Process any non-redirect errors thrown
|
|
2147
2212
|
if (isErrorResult(result)) {
|
|
2148
|
-
|
|
2149
|
-
state.fetchers.delete(key);
|
|
2150
|
-
// TODO: In remix, this would reset to IDLE_NAVIGATION if it was a catch -
|
|
2151
|
-
// do we need to behave any differently with our non-redirect errors?
|
|
2152
|
-
// What if it was a non-redirect Response?
|
|
2153
|
-
updateState({
|
|
2154
|
-
fetchers: new Map(state.fetchers),
|
|
2155
|
-
errors: {
|
|
2156
|
-
[boundaryMatch.route.id]: result.error,
|
|
2157
|
-
},
|
|
2158
|
-
});
|
|
2213
|
+
setFetcherError(key, routeId, result.error, { flushSync });
|
|
2159
2214
|
return;
|
|
2160
2215
|
}
|
|
2161
2216
|
|
|
2162
2217
|
invariant(!isDeferredResult(result), "Unhandled fetcher deferred data");
|
|
2163
2218
|
|
|
2164
2219
|
// Put the fetcher back into an idle state
|
|
2165
|
-
|
|
2166
|
-
state.fetchers.set(key, doneFetcher);
|
|
2167
|
-
updateState({ fetchers: new Map(state.fetchers) });
|
|
2220
|
+
updateFetcherState(key, getDoneFetcher(result.data), { flushSync });
|
|
2168
2221
|
}
|
|
2169
2222
|
|
|
2170
2223
|
/**
|
|
@@ -2373,15 +2426,47 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2373
2426
|
});
|
|
2374
2427
|
}
|
|
2375
2428
|
|
|
2376
|
-
function
|
|
2429
|
+
function updateFetcherState(
|
|
2430
|
+
key: string,
|
|
2431
|
+
fetcher: Fetcher,
|
|
2432
|
+
opts: { flushSync: boolean }
|
|
2433
|
+
) {
|
|
2434
|
+
state.fetchers.set(key, fetcher);
|
|
2435
|
+
updateState(
|
|
2436
|
+
{ fetchers: new Map(state.fetchers) },
|
|
2437
|
+
{ flushSync: opts.flushSync }
|
|
2438
|
+
);
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
function setFetcherError(
|
|
2442
|
+
key: string,
|
|
2443
|
+
routeId: string,
|
|
2444
|
+
error: any,
|
|
2445
|
+
opts: { flushSync: boolean }
|
|
2446
|
+
) {
|
|
2377
2447
|
let boundaryMatch = findNearestBoundary(state.matches, routeId);
|
|
2378
2448
|
deleteFetcher(key);
|
|
2379
|
-
updateState(
|
|
2380
|
-
|
|
2381
|
-
|
|
2449
|
+
updateState(
|
|
2450
|
+
{
|
|
2451
|
+
errors: {
|
|
2452
|
+
[boundaryMatch.route.id]: error,
|
|
2453
|
+
},
|
|
2454
|
+
fetchers: new Map(state.fetchers),
|
|
2382
2455
|
},
|
|
2383
|
-
|
|
2384
|
-
|
|
2456
|
+
{ flushSync: opts.flushSync }
|
|
2457
|
+
);
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
function getFetcher<TData = any>(key: string): Fetcher<TData> {
|
|
2461
|
+
if (future.v7_fetcherPersist) {
|
|
2462
|
+
activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1);
|
|
2463
|
+
// If this fetcher was previously marked for deletion, unmark it since we
|
|
2464
|
+
// have a new instance
|
|
2465
|
+
if (deletedFetchers.has(key)) {
|
|
2466
|
+
deletedFetchers.delete(key);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
return state.fetchers.get(key) || IDLE_FETCHER;
|
|
2385
2470
|
}
|
|
2386
2471
|
|
|
2387
2472
|
function deleteFetcher(key: string): void {
|
|
@@ -2404,11 +2489,17 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2404
2489
|
|
|
2405
2490
|
function deleteFetcherAndUpdateState(key: string): void {
|
|
2406
2491
|
if (future.v7_fetcherPersist) {
|
|
2407
|
-
|
|
2492
|
+
let count = (activeFetchers.get(key) || 0) - 1;
|
|
2493
|
+
if (count <= 0) {
|
|
2494
|
+
activeFetchers.delete(key);
|
|
2495
|
+
deletedFetchers.add(key);
|
|
2496
|
+
} else {
|
|
2497
|
+
activeFetchers.set(key, count);
|
|
2498
|
+
}
|
|
2408
2499
|
} else {
|
|
2409
2500
|
deleteFetcher(key);
|
|
2410
2501
|
}
|
|
2411
|
-
updateState({ fetchers: new Map(state.fetchers) });
|
|
2502
|
+
updateState({ fetchers: new Map(state.fetchers) }, { flushSync: false });
|
|
2412
2503
|
}
|
|
2413
2504
|
|
|
2414
2505
|
function abortFetcher(key: string) {
|
|
@@ -2491,7 +2582,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2491
2582
|
|
|
2492
2583
|
let blockers = new Map(state.blockers);
|
|
2493
2584
|
blockers.set(key, newBlocker);
|
|
2494
|
-
updateState({ blockers });
|
|
2585
|
+
updateState({ blockers }, { flushSync: false });
|
|
2495
2586
|
}
|
|
2496
2587
|
|
|
2497
2588
|
function shouldBlockNavigation({
|
|
@@ -2565,7 +2656,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2565
2656
|
initialScrollRestored = true;
|
|
2566
2657
|
let y = getSavedScrollPosition(state.location, state.matches);
|
|
2567
2658
|
if (y != null) {
|
|
2568
|
-
updateState({ restoreScrollPosition: y });
|
|
2659
|
+
updateState({ restoreScrollPosition: y }, { flushSync: false });
|
|
2569
2660
|
}
|
|
2570
2661
|
}
|
|
2571
2662
|
|