@remix-run/router 1.18.0 → 1.19.0-pre.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/index.d.ts +1 -1
- package/dist/router.cjs.js +83 -17
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +2 -1
- package/dist/router.js +77 -18
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +83 -17
- 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/dist/utils.d.ts +18 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/router.ts +69 -12
- package/utils.ts +35 -2
package/dist/router.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.
|
|
2
|
+
* @remix-run/router v1.19.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -1329,6 +1329,23 @@
|
|
|
1329
1329
|
headers
|
|
1330
1330
|
}));
|
|
1331
1331
|
};
|
|
1332
|
+
class DataWithResponseInit {
|
|
1333
|
+
constructor(data, init) {
|
|
1334
|
+
this.type = "DataWithResponseInit";
|
|
1335
|
+
this.data = data;
|
|
1336
|
+
this.init = init || null;
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
/**
|
|
1341
|
+
* Create "responses" that contain `status`/`headers` without forcing
|
|
1342
|
+
* serialization into an actual `Response` - used by Remix single fetch
|
|
1343
|
+
*/
|
|
1344
|
+
function data(data, init) {
|
|
1345
|
+
return new DataWithResponseInit(data, typeof init === "number" ? {
|
|
1346
|
+
status: init
|
|
1347
|
+
} : init);
|
|
1348
|
+
}
|
|
1332
1349
|
class AbortedDeferredError extends Error {}
|
|
1333
1350
|
class DeferredData {
|
|
1334
1351
|
constructor(data, responseInit) {
|
|
@@ -1511,6 +1528,18 @@
|
|
|
1511
1528
|
response.headers.set("X-Remix-Reload-Document", "true");
|
|
1512
1529
|
return response;
|
|
1513
1530
|
};
|
|
1531
|
+
|
|
1532
|
+
/**
|
|
1533
|
+
* A redirect response that will perform a `history.replaceState` instead of a
|
|
1534
|
+
* `history.pushState` for client-side navigation redirects.
|
|
1535
|
+
* Sets the status code and the `Location` header.
|
|
1536
|
+
* Defaults to "302 Found".
|
|
1537
|
+
*/
|
|
1538
|
+
const replace = (url, init) => {
|
|
1539
|
+
let response = redirect(url, init);
|
|
1540
|
+
response.headers.set("X-Remix-Replace", "true");
|
|
1541
|
+
return response;
|
|
1542
|
+
};
|
|
1514
1543
|
/**
|
|
1515
1544
|
* @private
|
|
1516
1545
|
* Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
|
|
@@ -1738,7 +1767,7 @@
|
|
|
1738
1767
|
// In SSR apps (with `hydrationData`), we expect that the server will send
|
|
1739
1768
|
// up the proper matched routes so we don't want to run lazy discovery on
|
|
1740
1769
|
// initial hydration and want to hydrate into the splat route.
|
|
1741
|
-
if (initialMatches &&
|
|
1770
|
+
if (initialMatches && !init.hydrationData) {
|
|
1742
1771
|
let fogOfWar = checkFogOfWar(initialMatches, dataRoutes, init.history.location.pathname);
|
|
1743
1772
|
if (fogOfWar.active) {
|
|
1744
1773
|
initialMatches = null;
|
|
@@ -1746,9 +1775,18 @@
|
|
|
1746
1775
|
}
|
|
1747
1776
|
let initialized;
|
|
1748
1777
|
if (!initialMatches) {
|
|
1749
|
-
// We need to run patchRoutesOnMiss in initialize()
|
|
1750
1778
|
initialized = false;
|
|
1751
1779
|
initialMatches = [];
|
|
1780
|
+
|
|
1781
|
+
// If partial hydration and fog of war is enabled, we will be running
|
|
1782
|
+
// `patchRoutesOnMiss` during hydration so include any partial matches as
|
|
1783
|
+
// the initial matches so we can properly render `HydrateFallback`'s
|
|
1784
|
+
if (future.v7_partialHydration) {
|
|
1785
|
+
let fogOfWar = checkFogOfWar(null, dataRoutes, init.history.location.pathname);
|
|
1786
|
+
if (fogOfWar.active && fogOfWar.matches) {
|
|
1787
|
+
initialMatches = fogOfWar.matches;
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1752
1790
|
} else if (initialMatches.some(m => m.route.lazy)) {
|
|
1753
1791
|
// All initialMatches need to be loaded before we're ready. If we have lazy
|
|
1754
1792
|
// functions around still then we'll need to run them in initialize()
|
|
@@ -1841,7 +1879,7 @@
|
|
|
1841
1879
|
|
|
1842
1880
|
// Use this internal array to capture fetcher loads that were cancelled by an
|
|
1843
1881
|
// action navigation and require revalidation
|
|
1844
|
-
let cancelledFetcherLoads =
|
|
1882
|
+
let cancelledFetcherLoads = new Set();
|
|
1845
1883
|
|
|
1846
1884
|
// AbortControllers for any in-flight fetchers
|
|
1847
1885
|
let fetchControllers = new Map();
|
|
@@ -2141,7 +2179,6 @@
|
|
|
2141
2179
|
isUninterruptedRevalidation = false;
|
|
2142
2180
|
isRevalidationRequired = false;
|
|
2143
2181
|
cancelledDeferredRoutes = [];
|
|
2144
|
-
cancelledFetcherLoads = [];
|
|
2145
2182
|
}
|
|
2146
2183
|
|
|
2147
2184
|
// Trigger a navigation event, which can either be a numerical POP or a PUSH
|
|
@@ -3143,7 +3180,7 @@
|
|
|
3143
3180
|
// There's no need to abort on redirects, since we don't detect the
|
|
3144
3181
|
// redirect until the action/loaders have settled
|
|
3145
3182
|
pendingNavigationController = null;
|
|
3146
|
-
let redirectHistoryAction = replace === true ? Action.Replace : Action.Push;
|
|
3183
|
+
let redirectHistoryAction = replace === true || redirect.response.headers.has("X-Remix-Replace") ? Action.Replace : Action.Push;
|
|
3147
3184
|
|
|
3148
3185
|
// Use the incoming submission if provided, fallback on the active one in
|
|
3149
3186
|
// state.navigation
|
|
@@ -3237,7 +3274,7 @@
|
|
|
3237
3274
|
// Abort in-flight fetcher loads
|
|
3238
3275
|
fetchLoadMatches.forEach((_, key) => {
|
|
3239
3276
|
if (fetchControllers.has(key)) {
|
|
3240
|
-
cancelledFetcherLoads.
|
|
3277
|
+
cancelledFetcherLoads.add(key);
|
|
3241
3278
|
abortFetcher(key);
|
|
3242
3279
|
}
|
|
3243
3280
|
});
|
|
@@ -3291,6 +3328,7 @@
|
|
|
3291
3328
|
fetchReloadIds.delete(key);
|
|
3292
3329
|
fetchRedirectIds.delete(key);
|
|
3293
3330
|
deletedFetchers.delete(key);
|
|
3331
|
+
cancelledFetcherLoads.delete(key);
|
|
3294
3332
|
state.fetchers.delete(key);
|
|
3295
3333
|
}
|
|
3296
3334
|
function deleteFetcherAndUpdateState(key) {
|
|
@@ -4406,8 +4444,9 @@
|
|
|
4406
4444
|
if (fetchRedirectIds.has(key)) {
|
|
4407
4445
|
// Never trigger a revalidation of an actively redirecting fetcher
|
|
4408
4446
|
shouldRevalidate = false;
|
|
4409
|
-
} else if (cancelledFetcherLoads.
|
|
4410
|
-
// Always
|
|
4447
|
+
} else if (cancelledFetcherLoads.has(key)) {
|
|
4448
|
+
// Always mark for revalidation if the fetcher was cancelled
|
|
4449
|
+
cancelledFetcherLoads.delete(key);
|
|
4411
4450
|
shouldRevalidate = true;
|
|
4412
4451
|
} else if (fetcher && fetcher.state !== "idle" && fetcher.data === undefined) {
|
|
4413
4452
|
// If the fetcher hasn't ever completed loading yet, then this isn't a
|
|
@@ -4729,8 +4768,7 @@
|
|
|
4729
4768
|
async function convertHandlerResultToDataResult(handlerResult) {
|
|
4730
4769
|
let {
|
|
4731
4770
|
result,
|
|
4732
|
-
type
|
|
4733
|
-
status
|
|
4771
|
+
type
|
|
4734
4772
|
} = handlerResult;
|
|
4735
4773
|
if (isResponse(result)) {
|
|
4736
4774
|
let data;
|
|
@@ -4769,25 +4807,47 @@
|
|
|
4769
4807
|
};
|
|
4770
4808
|
}
|
|
4771
4809
|
if (type === ResultType.error) {
|
|
4810
|
+
if (isDataWithResponseInit(result)) {
|
|
4811
|
+
var _result$init2;
|
|
4812
|
+
if (result.data instanceof Error) {
|
|
4813
|
+
var _result$init;
|
|
4814
|
+
return {
|
|
4815
|
+
type: ResultType.error,
|
|
4816
|
+
error: result.data,
|
|
4817
|
+
statusCode: (_result$init = result.init) == null ? void 0 : _result$init.status
|
|
4818
|
+
};
|
|
4819
|
+
}
|
|
4820
|
+
|
|
4821
|
+
// Convert thrown unstable_data() to ErrorResponse instances
|
|
4822
|
+
result = new ErrorResponseImpl(((_result$init2 = result.init) == null ? void 0 : _result$init2.status) || 500, undefined, result.data);
|
|
4823
|
+
}
|
|
4772
4824
|
return {
|
|
4773
4825
|
type: ResultType.error,
|
|
4774
4826
|
error: result,
|
|
4775
|
-
statusCode: isRouteErrorResponse(result) ? result.status :
|
|
4827
|
+
statusCode: isRouteErrorResponse(result) ? result.status : undefined
|
|
4776
4828
|
};
|
|
4777
4829
|
}
|
|
4778
4830
|
if (isDeferredData(result)) {
|
|
4779
|
-
var _result$
|
|
4831
|
+
var _result$init3, _result$init4;
|
|
4780
4832
|
return {
|
|
4781
4833
|
type: ResultType.deferred,
|
|
4782
4834
|
deferredData: result,
|
|
4783
|
-
statusCode: (_result$
|
|
4784
|
-
headers: ((_result$
|
|
4835
|
+
statusCode: (_result$init3 = result.init) == null ? void 0 : _result$init3.status,
|
|
4836
|
+
headers: ((_result$init4 = result.init) == null ? void 0 : _result$init4.headers) && new Headers(result.init.headers)
|
|
4837
|
+
};
|
|
4838
|
+
}
|
|
4839
|
+
if (isDataWithResponseInit(result)) {
|
|
4840
|
+
var _result$init5, _result$init6;
|
|
4841
|
+
return {
|
|
4842
|
+
type: ResultType.data,
|
|
4843
|
+
data: result.data,
|
|
4844
|
+
statusCode: (_result$init5 = result.init) == null ? void 0 : _result$init5.status,
|
|
4845
|
+
headers: (_result$init6 = result.init) != null && _result$init6.headers ? new Headers(result.init.headers) : undefined
|
|
4785
4846
|
};
|
|
4786
4847
|
}
|
|
4787
4848
|
return {
|
|
4788
4849
|
type: ResultType.data,
|
|
4789
|
-
data: result
|
|
4790
|
-
statusCode: status
|
|
4850
|
+
data: result
|
|
4791
4851
|
};
|
|
4792
4852
|
}
|
|
4793
4853
|
|
|
@@ -5150,6 +5210,9 @@
|
|
|
5150
5210
|
function isRedirectResult(result) {
|
|
5151
5211
|
return (result && result.type) === ResultType.redirect;
|
|
5152
5212
|
}
|
|
5213
|
+
function isDataWithResponseInit(value) {
|
|
5214
|
+
return typeof value === "object" && value != null && "type" in value && "data" in value && "init" in value && value.type === "DataWithResponseInit";
|
|
5215
|
+
}
|
|
5153
5216
|
function isDeferredData(value) {
|
|
5154
5217
|
let deferred = value;
|
|
5155
5218
|
return deferred && typeof deferred === "object" && typeof deferred.data === "object" && typeof deferred.subscribe === "function" && typeof deferred.cancel === "function" && typeof deferred.resolveData === "function";
|
|
@@ -5426,6 +5489,7 @@
|
|
|
5426
5489
|
exports.generatePath = generatePath;
|
|
5427
5490
|
exports.getStaticContextFromError = getStaticContextFromError;
|
|
5428
5491
|
exports.getToPathname = getToPathname;
|
|
5492
|
+
exports.isDataWithResponseInit = isDataWithResponseInit;
|
|
5429
5493
|
exports.isDeferredData = isDeferredData;
|
|
5430
5494
|
exports.isRouteErrorResponse = isRouteErrorResponse;
|
|
5431
5495
|
exports.joinPaths = joinPaths;
|
|
@@ -5436,9 +5500,11 @@
|
|
|
5436
5500
|
exports.parsePath = parsePath;
|
|
5437
5501
|
exports.redirect = redirect;
|
|
5438
5502
|
exports.redirectDocument = redirectDocument;
|
|
5503
|
+
exports.replace = replace;
|
|
5439
5504
|
exports.resolvePath = resolvePath;
|
|
5440
5505
|
exports.resolveTo = resolveTo;
|
|
5441
5506
|
exports.stripBasename = stripBasename;
|
|
5507
|
+
exports.unstable_data = data;
|
|
5442
5508
|
|
|
5443
5509
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5444
5510
|
|