@remix-run/router 1.11.0 → 1.12.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/CHANGELOG.md +28 -0
- package/dist/router.cjs.js +121 -84
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +2 -0
- package/dist/router.js +119 -84
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +121 -84
- 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 +149 -87
- package/utils.ts +23 -4
package/dist/router.d.ts
CHANGED
|
@@ -306,6 +306,7 @@ export interface RouterSubscriber {
|
|
|
306
306
|
(state: RouterState, opts: {
|
|
307
307
|
deletedFetchers: string[];
|
|
308
308
|
unstable_viewTransitionOpts?: ViewTransitionOpts;
|
|
309
|
+
unstable_flushSync: boolean;
|
|
309
310
|
}): void;
|
|
310
311
|
}
|
|
311
312
|
/**
|
|
@@ -325,6 +326,7 @@ export type RelativeRoutingType = "route" | "path";
|
|
|
325
326
|
type BaseNavigateOrFetchOptions = {
|
|
326
327
|
preventScrollReset?: boolean;
|
|
327
328
|
relative?: RelativeRoutingType;
|
|
329
|
+
unstable_flushSync?: boolean;
|
|
328
330
|
};
|
|
329
331
|
type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
|
|
330
332
|
replace?: boolean;
|
package/dist/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.
|
|
2
|
+
* @remix-run/router v1.12.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -966,15 +966,28 @@ function resolveTo(toArg, routePathnames, locationPathname, isPathRelative) {
|
|
|
966
966
|
// `to` values that do not provide a pathname. `to` can simply be a search or
|
|
967
967
|
// hash string, in which case we should assume that the navigation is relative
|
|
968
968
|
// to the current location's pathname and *not* the route pathname.
|
|
969
|
-
if (
|
|
969
|
+
if (toPathname == null) {
|
|
970
970
|
from = locationPathname;
|
|
971
|
+
} else if (isPathRelative) {
|
|
972
|
+
let fromSegments = routePathnames[routePathnames.length - 1].replace(/^\//, "").split("/");
|
|
973
|
+
if (toPathname.startsWith("..")) {
|
|
974
|
+
let toSegments = toPathname.split("/");
|
|
975
|
+
// With relative="path", each leading .. segment means "go up one URL segment"
|
|
976
|
+
while (toSegments[0] === "..") {
|
|
977
|
+
toSegments.shift();
|
|
978
|
+
fromSegments.pop();
|
|
979
|
+
}
|
|
980
|
+
to.pathname = toSegments.join("/");
|
|
981
|
+
}
|
|
982
|
+
from = "/" + fromSegments.join("/");
|
|
971
983
|
} else {
|
|
972
984
|
let routePathnameIndex = routePathnames.length - 1;
|
|
973
985
|
if (toPathname.startsWith("..")) {
|
|
974
986
|
let toSegments = toPathname.split("/");
|
|
975
|
-
//
|
|
976
|
-
// URL segment". This is a key
|
|
977
|
-
//
|
|
987
|
+
// With relative="route" (the default), each leading .. segment means
|
|
988
|
+
// "go up one route" instead of "go up one URL segment". This is a key
|
|
989
|
+
// difference from how <a href> works and a major reason we call this a
|
|
990
|
+
// "to" value instead of a "href".
|
|
978
991
|
while (toSegments[0] === "..") {
|
|
979
992
|
toSegments.shift();
|
|
980
993
|
routePathnameIndex -= 1;
|
|
@@ -1525,7 +1538,10 @@ function createRouter(init) {
|
|
|
1525
1538
|
return () => subscribers.delete(fn);
|
|
1526
1539
|
}
|
|
1527
1540
|
// Update our state and notify the calling context of the change
|
|
1528
|
-
function updateState(newState,
|
|
1541
|
+
function updateState(newState, opts) {
|
|
1542
|
+
if (opts === void 0) {
|
|
1543
|
+
opts = {};
|
|
1544
|
+
}
|
|
1529
1545
|
state = _extends({}, state, newState);
|
|
1530
1546
|
// Prep fetcher cleanup so we can tell the UI which fetcher data entries
|
|
1531
1547
|
// can be removed
|
|
@@ -1545,9 +1561,13 @@ function createRouter(init) {
|
|
|
1545
1561
|
}
|
|
1546
1562
|
});
|
|
1547
1563
|
}
|
|
1548
|
-
|
|
1564
|
+
// Iterate over a local copy so that if flushSync is used and we end up
|
|
1565
|
+
// removing and adding a new subscriber due to the useCallback dependencies,
|
|
1566
|
+
// we don't get ourselves into a loop calling the new subscriber immediately
|
|
1567
|
+
[...subscribers].forEach(subscriber => subscriber(state, {
|
|
1549
1568
|
deletedFetchers: deletedFetchersKeys,
|
|
1550
|
-
unstable_viewTransitionOpts: viewTransitionOpts
|
|
1569
|
+
unstable_viewTransitionOpts: opts.viewTransitionOpts,
|
|
1570
|
+
unstable_flushSync: opts.flushSync === true
|
|
1551
1571
|
}));
|
|
1552
1572
|
// Remove idle fetchers from state since we only care about in-flight fetchers.
|
|
1553
1573
|
if (future.v7_fetcherPersist) {
|
|
@@ -1560,8 +1580,11 @@ function createRouter(init) {
|
|
|
1560
1580
|
// - Location is a required param
|
|
1561
1581
|
// - Navigation will always be set to IDLE_NAVIGATION
|
|
1562
1582
|
// - Can pass any other state in newState
|
|
1563
|
-
function completeNavigation(location, newState) {
|
|
1583
|
+
function completeNavigation(location, newState, _temp) {
|
|
1564
1584
|
var _location$state, _location$state2;
|
|
1585
|
+
let {
|
|
1586
|
+
flushSync
|
|
1587
|
+
} = _temp === void 0 ? {} : _temp;
|
|
1565
1588
|
// Deduce if we're in a loading/actionReload state:
|
|
1566
1589
|
// - We have committed actionData in the store
|
|
1567
1590
|
// - The current navigation was a mutation submission
|
|
@@ -1647,7 +1670,10 @@ function createRouter(init) {
|
|
|
1647
1670
|
restoreScrollPosition: getSavedScrollPosition(location, newState.matches || state.matches),
|
|
1648
1671
|
preventScrollReset,
|
|
1649
1672
|
blockers
|
|
1650
|
-
}),
|
|
1673
|
+
}), {
|
|
1674
|
+
viewTransitionOpts,
|
|
1675
|
+
flushSync: flushSync === true
|
|
1676
|
+
});
|
|
1651
1677
|
// Reset stateful navigation vars
|
|
1652
1678
|
pendingAction = Action.Pop;
|
|
1653
1679
|
pendingPreventScrollReset = false;
|
|
@@ -1690,6 +1716,7 @@ function createRouter(init) {
|
|
|
1690
1716
|
historyAction = Action.Replace;
|
|
1691
1717
|
}
|
|
1692
1718
|
let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : undefined;
|
|
1719
|
+
let flushSync = (opts && opts.unstable_flushSync) === true;
|
|
1693
1720
|
let blockerKey = shouldBlockNavigation({
|
|
1694
1721
|
currentLocation,
|
|
1695
1722
|
nextLocation,
|
|
@@ -1727,7 +1754,8 @@ function createRouter(init) {
|
|
|
1727
1754
|
pendingError: error,
|
|
1728
1755
|
preventScrollReset,
|
|
1729
1756
|
replace: opts && opts.replace,
|
|
1730
|
-
enableViewTransition: opts && opts.unstable_viewTransition
|
|
1757
|
+
enableViewTransition: opts && opts.unstable_viewTransition,
|
|
1758
|
+
flushSync
|
|
1731
1759
|
});
|
|
1732
1760
|
}
|
|
1733
1761
|
// Revalidate all current loaders. If a navigation is in progress or if this
|
|
@@ -1778,6 +1806,7 @@ function createRouter(init) {
|
|
|
1778
1806
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
1779
1807
|
let loadingNavigation = opts && opts.overrideNavigation;
|
|
1780
1808
|
let matches = matchRoutes(routesToUse, location, basename);
|
|
1809
|
+
let flushSync = (opts && opts.flushSync) === true;
|
|
1781
1810
|
// Short circuit with a 404 on the root error boundary if we match nothing
|
|
1782
1811
|
if (!matches) {
|
|
1783
1812
|
let error = getInternalRouterError(404, {
|
|
@@ -1795,6 +1824,8 @@ function createRouter(init) {
|
|
|
1795
1824
|
errors: {
|
|
1796
1825
|
[route.id]: error
|
|
1797
1826
|
}
|
|
1827
|
+
}, {
|
|
1828
|
+
flushSync
|
|
1798
1829
|
});
|
|
1799
1830
|
return;
|
|
1800
1831
|
}
|
|
@@ -1807,6 +1838,8 @@ function createRouter(init) {
|
|
|
1807
1838
|
if (state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
|
|
1808
1839
|
completeNavigation(location, {
|
|
1809
1840
|
matches
|
|
1841
|
+
}, {
|
|
1842
|
+
flushSync
|
|
1810
1843
|
});
|
|
1811
1844
|
return;
|
|
1812
1845
|
}
|
|
@@ -1826,7 +1859,8 @@ function createRouter(init) {
|
|
|
1826
1859
|
} else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) {
|
|
1827
1860
|
// Call action if we received an action submission
|
|
1828
1861
|
let actionOutput = await handleAction(request, location, opts.submission, matches, {
|
|
1829
|
-
replace: opts.replace
|
|
1862
|
+
replace: opts.replace,
|
|
1863
|
+
flushSync
|
|
1830
1864
|
});
|
|
1831
1865
|
if (actionOutput.shortCircuited) {
|
|
1832
1866
|
return;
|
|
@@ -1834,6 +1868,7 @@ function createRouter(init) {
|
|
|
1834
1868
|
pendingActionData = actionOutput.pendingActionData;
|
|
1835
1869
|
pendingError = actionOutput.pendingActionError;
|
|
1836
1870
|
loadingNavigation = getLoadingNavigation(location, opts.submission);
|
|
1871
|
+
flushSync = false;
|
|
1837
1872
|
// Create a GET request for the loaders
|
|
1838
1873
|
request = new Request(request.url, {
|
|
1839
1874
|
signal: request.signal
|
|
@@ -1844,7 +1879,7 @@ function createRouter(init) {
|
|
|
1844
1879
|
shortCircuited,
|
|
1845
1880
|
loaderData,
|
|
1846
1881
|
errors
|
|
1847
|
-
} = await handleLoaders(request, location, matches, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, pendingActionData, pendingError);
|
|
1882
|
+
} = await handleLoaders(request, location, matches, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, flushSync, pendingActionData, pendingError);
|
|
1848
1883
|
if (shortCircuited) {
|
|
1849
1884
|
return;
|
|
1850
1885
|
}
|
|
@@ -1872,6 +1907,8 @@ function createRouter(init) {
|
|
|
1872
1907
|
let navigation = getSubmittingNavigation(location, submission);
|
|
1873
1908
|
updateState({
|
|
1874
1909
|
navigation
|
|
1910
|
+
}, {
|
|
1911
|
+
flushSync: opts.flushSync === true
|
|
1875
1912
|
});
|
|
1876
1913
|
// Call our action and get the result
|
|
1877
1914
|
let result;
|
|
@@ -1943,7 +1980,7 @@ function createRouter(init) {
|
|
|
1943
1980
|
}
|
|
1944
1981
|
// Call all applicable loaders for the given matches, handling redirects,
|
|
1945
1982
|
// errors, etc.
|
|
1946
|
-
async function handleLoaders(request, location, matches, overrideNavigation, submission, fetcherSubmission, replace, pendingActionData, pendingError) {
|
|
1983
|
+
async function handleLoaders(request, location, matches, overrideNavigation, submission, fetcherSubmission, replace, flushSync, pendingActionData, pendingError) {
|
|
1947
1984
|
// Figure out the right navigation we want to use for data loading
|
|
1948
1985
|
let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
|
|
1949
1986
|
// If this was a redirect from an action we don't have a "submission" but
|
|
@@ -1968,7 +2005,9 @@ function createRouter(init) {
|
|
|
1968
2005
|
actionData: pendingActionData
|
|
1969
2006
|
} : {}, updatedFetchers ? {
|
|
1970
2007
|
fetchers: new Map(state.fetchers)
|
|
1971
|
-
} : {})
|
|
2008
|
+
} : {}), {
|
|
2009
|
+
flushSync
|
|
2010
|
+
});
|
|
1972
2011
|
return {
|
|
1973
2012
|
shortCircuited: true
|
|
1974
2013
|
};
|
|
@@ -1992,7 +2031,9 @@ function createRouter(init) {
|
|
|
1992
2031
|
actionData
|
|
1993
2032
|
} : {}, revalidatingFetchers.length > 0 ? {
|
|
1994
2033
|
fetchers: new Map(state.fetchers)
|
|
1995
|
-
} : {})
|
|
2034
|
+
} : {}), {
|
|
2035
|
+
flushSync
|
|
2036
|
+
});
|
|
1996
2037
|
}
|
|
1997
2038
|
revalidatingFetchers.forEach(rf => {
|
|
1998
2039
|
if (fetchControllers.has(rf.key)) {
|
|
@@ -2070,30 +2111,22 @@ function createRouter(init) {
|
|
|
2070
2111
|
fetchers: new Map(state.fetchers)
|
|
2071
2112
|
} : {});
|
|
2072
2113
|
}
|
|
2073
|
-
function getFetcher(key) {
|
|
2074
|
-
if (future.v7_fetcherPersist) {
|
|
2075
|
-
activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1);
|
|
2076
|
-
// If this fetcher was previously marked for deletion, unmark it since we
|
|
2077
|
-
// have a new instance
|
|
2078
|
-
if (deletedFetchers.has(key)) {
|
|
2079
|
-
deletedFetchers.delete(key);
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
return state.fetchers.get(key) || IDLE_FETCHER;
|
|
2083
|
-
}
|
|
2084
2114
|
// Trigger a fetcher load/submit for the given fetcher key
|
|
2085
2115
|
function fetch(key, routeId, href, opts) {
|
|
2086
2116
|
if (isServer) {
|
|
2087
2117
|
throw new Error("router.fetch() was called during the server render, but it shouldn't be. " + "You are likely calling a useFetcher() method in the body of your component. " + "Try moving it to a useEffect or a callback.");
|
|
2088
2118
|
}
|
|
2089
2119
|
if (fetchControllers.has(key)) abortFetcher(key);
|
|
2120
|
+
let flushSync = (opts && opts.unstable_flushSync) === true;
|
|
2090
2121
|
let routesToUse = inFlightDataRoutes || dataRoutes;
|
|
2091
2122
|
let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, href, routeId, opts == null ? void 0 : opts.relative);
|
|
2092
2123
|
let matches = matchRoutes(routesToUse, normalizedPath, basename);
|
|
2093
2124
|
if (!matches) {
|
|
2094
2125
|
setFetcherError(key, routeId, getInternalRouterError(404, {
|
|
2095
2126
|
pathname: normalizedPath
|
|
2096
|
-
})
|
|
2127
|
+
}), {
|
|
2128
|
+
flushSync
|
|
2129
|
+
});
|
|
2097
2130
|
return;
|
|
2098
2131
|
}
|
|
2099
2132
|
let {
|
|
@@ -2102,13 +2135,15 @@ function createRouter(init) {
|
|
|
2102
2135
|
error
|
|
2103
2136
|
} = normalizeNavigateOptions(future.v7_normalizeFormMethod, true, normalizedPath, opts);
|
|
2104
2137
|
if (error) {
|
|
2105
|
-
setFetcherError(key, routeId, error
|
|
2138
|
+
setFetcherError(key, routeId, error, {
|
|
2139
|
+
flushSync
|
|
2140
|
+
});
|
|
2106
2141
|
return;
|
|
2107
2142
|
}
|
|
2108
2143
|
let match = getTargetMatch(matches, path);
|
|
2109
2144
|
pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
|
|
2110
2145
|
if (submission && isMutationMethod(submission.formMethod)) {
|
|
2111
|
-
handleFetcherAction(key, routeId, path, match, matches, submission);
|
|
2146
|
+
handleFetcherAction(key, routeId, path, match, matches, flushSync, submission);
|
|
2112
2147
|
return;
|
|
2113
2148
|
}
|
|
2114
2149
|
// Store off the match so we can call it's shouldRevalidate on subsequent
|
|
@@ -2117,11 +2152,11 @@ function createRouter(init) {
|
|
|
2117
2152
|
routeId,
|
|
2118
2153
|
path
|
|
2119
2154
|
});
|
|
2120
|
-
handleFetcherLoader(key, routeId, path, match, matches, submission);
|
|
2155
|
+
handleFetcherLoader(key, routeId, path, match, matches, flushSync, submission);
|
|
2121
2156
|
}
|
|
2122
2157
|
// Call the action for the matched fetcher.submit(), and then handle redirects,
|
|
2123
2158
|
// errors, and revalidation
|
|
2124
|
-
async function handleFetcherAction(key, routeId, path, match, requestMatches, submission) {
|
|
2159
|
+
async function handleFetcherAction(key, routeId, path, match, requestMatches, flushSync, submission) {
|
|
2125
2160
|
interruptActiveLoads();
|
|
2126
2161
|
fetchLoadMatches.delete(key);
|
|
2127
2162
|
if (!match.route.action && !match.route.lazy) {
|
|
@@ -2130,15 +2165,15 @@ function createRouter(init) {
|
|
|
2130
2165
|
pathname: path,
|
|
2131
2166
|
routeId: routeId
|
|
2132
2167
|
});
|
|
2133
|
-
setFetcherError(key, routeId, error
|
|
2168
|
+
setFetcherError(key, routeId, error, {
|
|
2169
|
+
flushSync
|
|
2170
|
+
});
|
|
2134
2171
|
return;
|
|
2135
2172
|
}
|
|
2136
2173
|
// Put this fetcher into it's submitting state
|
|
2137
2174
|
let existingFetcher = state.fetchers.get(key);
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
updateState({
|
|
2141
|
-
fetchers: new Map(state.fetchers)
|
|
2175
|
+
updateFetcherState(key, getSubmittingFetcher(submission, existingFetcher), {
|
|
2176
|
+
flushSync
|
|
2142
2177
|
});
|
|
2143
2178
|
// Call the action for the fetcher
|
|
2144
2179
|
let abortController = new AbortController();
|
|
@@ -2155,10 +2190,7 @@ function createRouter(init) {
|
|
|
2155
2190
|
return;
|
|
2156
2191
|
}
|
|
2157
2192
|
if (deletedFetchers.has(key)) {
|
|
2158
|
-
|
|
2159
|
-
updateState({
|
|
2160
|
-
fetchers: new Map(state.fetchers)
|
|
2161
|
-
});
|
|
2193
|
+
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2162
2194
|
return;
|
|
2163
2195
|
}
|
|
2164
2196
|
if (isRedirectResult(actionResult)) {
|
|
@@ -2168,19 +2200,11 @@ function createRouter(init) {
|
|
|
2168
2200
|
// should take precedence over this redirect navigation. We already
|
|
2169
2201
|
// set isRevalidationRequired so all loaders for the new route should
|
|
2170
2202
|
// fire unless opted out via shouldRevalidate
|
|
2171
|
-
|
|
2172
|
-
state.fetchers.set(key, doneFetcher);
|
|
2173
|
-
updateState({
|
|
2174
|
-
fetchers: new Map(state.fetchers)
|
|
2175
|
-
});
|
|
2203
|
+
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2176
2204
|
return;
|
|
2177
2205
|
} else {
|
|
2178
2206
|
fetchRedirectIds.add(key);
|
|
2179
|
-
|
|
2180
|
-
state.fetchers.set(key, loadingFetcher);
|
|
2181
|
-
updateState({
|
|
2182
|
-
fetchers: new Map(state.fetchers)
|
|
2183
|
-
});
|
|
2207
|
+
updateFetcherState(key, getLoadingFetcher(submission));
|
|
2184
2208
|
return startRedirectNavigation(state, actionResult, {
|
|
2185
2209
|
fetcherSubmission: submission
|
|
2186
2210
|
});
|
|
@@ -2291,13 +2315,10 @@ function createRouter(init) {
|
|
|
2291
2315
|
}
|
|
2292
2316
|
}
|
|
2293
2317
|
// Call the matched loader for fetcher.load(), handling redirects, errors, etc.
|
|
2294
|
-
async function handleFetcherLoader(key, routeId, path, match, matches, submission) {
|
|
2318
|
+
async function handleFetcherLoader(key, routeId, path, match, matches, flushSync, submission) {
|
|
2295
2319
|
let existingFetcher = state.fetchers.get(key);
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
state.fetchers.set(key, loadingFetcher);
|
|
2299
|
-
updateState({
|
|
2300
|
-
fetchers: new Map(state.fetchers)
|
|
2320
|
+
updateFetcherState(key, getLoadingFetcher(submission, existingFetcher ? existingFetcher.data : undefined), {
|
|
2321
|
+
flushSync
|
|
2301
2322
|
});
|
|
2302
2323
|
// Call the loader for this fetcher route match
|
|
2303
2324
|
let abortController = new AbortController();
|
|
@@ -2321,10 +2342,7 @@ function createRouter(init) {
|
|
|
2321
2342
|
return;
|
|
2322
2343
|
}
|
|
2323
2344
|
if (deletedFetchers.has(key)) {
|
|
2324
|
-
|
|
2325
|
-
updateState({
|
|
2326
|
-
fetchers: new Map(state.fetchers)
|
|
2327
|
-
});
|
|
2345
|
+
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2328
2346
|
return;
|
|
2329
2347
|
}
|
|
2330
2348
|
// If the loader threw a redirect Response, start a new REPLACE navigation
|
|
@@ -2332,11 +2350,7 @@ function createRouter(init) {
|
|
|
2332
2350
|
if (pendingNavigationLoadId > originatingLoadId) {
|
|
2333
2351
|
// A new navigation was kicked off after our loader started, so that
|
|
2334
2352
|
// should take precedence over this redirect navigation
|
|
2335
|
-
|
|
2336
|
-
state.fetchers.set(key, doneFetcher);
|
|
2337
|
-
updateState({
|
|
2338
|
-
fetchers: new Map(state.fetchers)
|
|
2339
|
-
});
|
|
2353
|
+
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2340
2354
|
return;
|
|
2341
2355
|
} else {
|
|
2342
2356
|
fetchRedirectIds.add(key);
|
|
@@ -2351,11 +2365,7 @@ function createRouter(init) {
|
|
|
2351
2365
|
}
|
|
2352
2366
|
invariant(!isDeferredResult(result), "Unhandled fetcher deferred data");
|
|
2353
2367
|
// Put the fetcher back into an idle state
|
|
2354
|
-
|
|
2355
|
-
state.fetchers.set(key, doneFetcher);
|
|
2356
|
-
updateState({
|
|
2357
|
-
fetchers: new Map(state.fetchers)
|
|
2358
|
-
});
|
|
2368
|
+
updateFetcherState(key, getDoneFetcher(result.data));
|
|
2359
2369
|
}
|
|
2360
2370
|
/**
|
|
2361
2371
|
* Utility function to handle redirects returned from an action or loader.
|
|
@@ -2376,12 +2386,12 @@ function createRouter(init) {
|
|
|
2376
2386
|
* actually touch history until we've processed redirects, so we just use
|
|
2377
2387
|
* the history action from the original navigation (PUSH or REPLACE).
|
|
2378
2388
|
*/
|
|
2379
|
-
async function startRedirectNavigation(state, redirect,
|
|
2389
|
+
async function startRedirectNavigation(state, redirect, _temp2) {
|
|
2380
2390
|
let {
|
|
2381
2391
|
submission,
|
|
2382
2392
|
fetcherSubmission,
|
|
2383
2393
|
replace
|
|
2384
|
-
} =
|
|
2394
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2385
2395
|
if (redirect.revalidate) {
|
|
2386
2396
|
isRevalidationRequired = true;
|
|
2387
2397
|
}
|
|
@@ -2490,7 +2500,21 @@ function createRouter(init) {
|
|
|
2490
2500
|
}
|
|
2491
2501
|
});
|
|
2492
2502
|
}
|
|
2493
|
-
function
|
|
2503
|
+
function updateFetcherState(key, fetcher, opts) {
|
|
2504
|
+
if (opts === void 0) {
|
|
2505
|
+
opts = {};
|
|
2506
|
+
}
|
|
2507
|
+
state.fetchers.set(key, fetcher);
|
|
2508
|
+
updateState({
|
|
2509
|
+
fetchers: new Map(state.fetchers)
|
|
2510
|
+
}, {
|
|
2511
|
+
flushSync: (opts && opts.flushSync) === true
|
|
2512
|
+
});
|
|
2513
|
+
}
|
|
2514
|
+
function setFetcherError(key, routeId, error, opts) {
|
|
2515
|
+
if (opts === void 0) {
|
|
2516
|
+
opts = {};
|
|
2517
|
+
}
|
|
2494
2518
|
let boundaryMatch = findNearestBoundary(state.matches, routeId);
|
|
2495
2519
|
deleteFetcher(key);
|
|
2496
2520
|
updateState({
|
|
@@ -2498,8 +2522,21 @@ function createRouter(init) {
|
|
|
2498
2522
|
[boundaryMatch.route.id]: error
|
|
2499
2523
|
},
|
|
2500
2524
|
fetchers: new Map(state.fetchers)
|
|
2525
|
+
}, {
|
|
2526
|
+
flushSync: (opts && opts.flushSync) === true
|
|
2501
2527
|
});
|
|
2502
2528
|
}
|
|
2529
|
+
function getFetcher(key) {
|
|
2530
|
+
if (future.v7_fetcherPersist) {
|
|
2531
|
+
activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1);
|
|
2532
|
+
// If this fetcher was previously marked for deletion, unmark it since we
|
|
2533
|
+
// have a new instance
|
|
2534
|
+
if (deletedFetchers.has(key)) {
|
|
2535
|
+
deletedFetchers.delete(key);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
return state.fetchers.get(key) || IDLE_FETCHER;
|
|
2539
|
+
}
|
|
2503
2540
|
function deleteFetcher(key) {
|
|
2504
2541
|
let fetcher = state.fetchers.get(key);
|
|
2505
2542
|
// Don't abort the controller if this is a deletion of a fetcher.submit()
|
|
@@ -2771,10 +2808,10 @@ function createStaticHandler(routes, opts) {
|
|
|
2771
2808
|
* propagate that out and return the raw Response so the HTTP server can
|
|
2772
2809
|
* return it directly.
|
|
2773
2810
|
*/
|
|
2774
|
-
async function query(request,
|
|
2811
|
+
async function query(request, _temp3) {
|
|
2775
2812
|
let {
|
|
2776
2813
|
requestContext
|
|
2777
|
-
} =
|
|
2814
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
2778
2815
|
let url = new URL(request.url);
|
|
2779
2816
|
let method = request.method;
|
|
2780
2817
|
let location = createLocation("", createPath(url), null, "default");
|
|
@@ -2857,11 +2894,11 @@ function createStaticHandler(routes, opts) {
|
|
|
2857
2894
|
* code. Examples here are 404 and 405 errors that occur prior to reaching
|
|
2858
2895
|
* any user-defined loaders.
|
|
2859
2896
|
*/
|
|
2860
|
-
async function queryRoute(request,
|
|
2897
|
+
async function queryRoute(request, _temp4) {
|
|
2861
2898
|
let {
|
|
2862
2899
|
routeId,
|
|
2863
2900
|
requestContext
|
|
2864
|
-
} =
|
|
2901
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
2865
2902
|
let url = new URL(request.url);
|
|
2866
2903
|
let method = request.method;
|
|
2867
2904
|
let location = createLocation("", createPath(url), null, "default");
|
|
@@ -3128,11 +3165,9 @@ function isSubmissionNavigation(opts) {
|
|
|
3128
3165
|
function normalizeTo(location, matches, basename, prependBasename, to, fromRouteId, relative) {
|
|
3129
3166
|
let contextualMatches;
|
|
3130
3167
|
let activeRouteMatch;
|
|
3131
|
-
if (fromRouteId
|
|
3168
|
+
if (fromRouteId) {
|
|
3132
3169
|
// Grab matches up to the calling route so our route-relative logic is
|
|
3133
|
-
// relative to the correct source route
|
|
3134
|
-
// fromRouteId is ignored since that is always relative to the current
|
|
3135
|
-
// location path
|
|
3170
|
+
// relative to the correct source route
|
|
3136
3171
|
contextualMatches = [];
|
|
3137
3172
|
for (let match of matches) {
|
|
3138
3173
|
contextualMatches.push(match);
|
|
@@ -3864,13 +3899,13 @@ function getShortCircuitMatches(routes) {
|
|
|
3864
3899
|
route
|
|
3865
3900
|
};
|
|
3866
3901
|
}
|
|
3867
|
-
function getInternalRouterError(status,
|
|
3902
|
+
function getInternalRouterError(status, _temp5) {
|
|
3868
3903
|
let {
|
|
3869
3904
|
pathname,
|
|
3870
3905
|
routeId,
|
|
3871
3906
|
method,
|
|
3872
3907
|
type
|
|
3873
|
-
} =
|
|
3908
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
3874
3909
|
let statusText = "Unknown Server Error";
|
|
3875
3910
|
let errorMessage = "Unknown @remix-run/router error";
|
|
3876
3911
|
if (status === 400) {
|