@remix-run/router 1.0.5-pre.0 → 1.0.5-pre.2
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 +14 -0
- package/dist/router.cjs.js +56 -44
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +7 -2
- package/dist/router.js +56 -44
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +56 -44
- 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 +1 -1
- package/package.json +1 -1
- package/router.ts +82 -41
- package/utils.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# `@remix-run/router`
|
|
2
2
|
|
|
3
|
+
## 1.0.5-pre.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `requestContext` support to static handler `query`/`queryRoute` ([#9696](https://github.com/remix-run/react-router/pull/9696))
|
|
8
|
+
- Note that the unstable API of `queryRoute(path, routeId)` has been changed to `queryRoute(path, { routeId, requestContext })`
|
|
9
|
+
|
|
10
|
+
## 1.0.5-pre.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Remove `instanceof Response` checks in favor of `isResponse` ([#9690](https://github.com/remix-run/react-router/pull/9690))
|
|
15
|
+
- Fix URL creation in Remix integration tests ([#9689](https://github.com/remix-run/react-router/pull/9689))
|
|
16
|
+
|
|
3
17
|
## 1.0.5-pre.0
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.0.5-pre.
|
|
2
|
+
* @remix-run/router v1.0.5-pre.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -2193,21 +2193,27 @@ function createRouter(init) {
|
|
|
2193
2193
|
|
|
2194
2194
|
|
|
2195
2195
|
async function startRedirectNavigation(state, redirect, replace) {
|
|
2196
|
+
var _window;
|
|
2197
|
+
|
|
2196
2198
|
if (redirect.revalidate) {
|
|
2197
2199
|
isRevalidationRequired = true;
|
|
2198
2200
|
}
|
|
2199
2201
|
|
|
2200
2202
|
let redirectLocation = createLocation(state.location, redirect.location);
|
|
2201
|
-
invariant(redirectLocation, "Expected a location on the redirect navigation");
|
|
2203
|
+
invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an external redirect that goes to a new origin
|
|
2202
2204
|
|
|
2203
|
-
if (
|
|
2204
|
-
|
|
2205
|
-
window.location.replace(redirect.location);
|
|
2206
|
-
} else {
|
|
2207
|
-
window.location.assign(redirect.location);
|
|
2208
|
-
}
|
|
2205
|
+
if (typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
|
|
2206
|
+
let newOrigin = createClientSideURL(redirect.location).origin;
|
|
2209
2207
|
|
|
2210
|
-
|
|
2208
|
+
if (window.location.origin !== newOrigin) {
|
|
2209
|
+
if (replace) {
|
|
2210
|
+
window.location.replace(redirect.location);
|
|
2211
|
+
} else {
|
|
2212
|
+
window.location.assign(redirect.location);
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
return;
|
|
2216
|
+
}
|
|
2211
2217
|
} // There's no need to abort on redirects, since we don't detect the
|
|
2212
2218
|
// redirect until the action/loaders have settled
|
|
2213
2219
|
|
|
@@ -2486,7 +2492,10 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2486
2492
|
* return it directly.
|
|
2487
2493
|
*/
|
|
2488
2494
|
|
|
2489
|
-
async function query(request) {
|
|
2495
|
+
async function query(request, _temp) {
|
|
2496
|
+
let {
|
|
2497
|
+
requestContext
|
|
2498
|
+
} = _temp === void 0 ? {} : _temp;
|
|
2490
2499
|
let url = new URL(request.url);
|
|
2491
2500
|
let method = request.method.toLowerCase();
|
|
2492
2501
|
let location = createLocation("", createPath(url), null, "default");
|
|
@@ -2536,9 +2545,9 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2536
2545
|
};
|
|
2537
2546
|
}
|
|
2538
2547
|
|
|
2539
|
-
let result = await queryImpl(request, location, matches);
|
|
2548
|
+
let result = await queryImpl(request, location, matches, requestContext);
|
|
2540
2549
|
|
|
2541
|
-
if (result
|
|
2550
|
+
if (isResponse(result)) {
|
|
2542
2551
|
return result;
|
|
2543
2552
|
} // When returning StaticHandlerContext, we patch back in the location here
|
|
2544
2553
|
// since we need it for React Context. But this helps keep our submit and
|
|
@@ -2572,7 +2581,11 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2572
2581
|
*/
|
|
2573
2582
|
|
|
2574
2583
|
|
|
2575
|
-
async function queryRoute(request,
|
|
2584
|
+
async function queryRoute(request, _temp2) {
|
|
2585
|
+
let {
|
|
2586
|
+
routeId,
|
|
2587
|
+
requestContext
|
|
2588
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2576
2589
|
let url = new URL(request.url);
|
|
2577
2590
|
let method = request.method.toLowerCase();
|
|
2578
2591
|
let location = createLocation("", createPath(url), null, "default");
|
|
@@ -2602,9 +2615,9 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2602
2615
|
});
|
|
2603
2616
|
}
|
|
2604
2617
|
|
|
2605
|
-
let result = await queryImpl(request, location, matches, match);
|
|
2618
|
+
let result = await queryImpl(request, location, matches, requestContext, match);
|
|
2606
2619
|
|
|
2607
|
-
if (result
|
|
2620
|
+
if (isResponse(result)) {
|
|
2608
2621
|
return result;
|
|
2609
2622
|
}
|
|
2610
2623
|
|
|
@@ -2623,17 +2636,17 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2623
2636
|
return Object.values(routeData || {})[0];
|
|
2624
2637
|
}
|
|
2625
2638
|
|
|
2626
|
-
async function queryImpl(request, location, matches, routeMatch) {
|
|
2639
|
+
async function queryImpl(request, location, matches, requestContext, routeMatch) {
|
|
2627
2640
|
invariant(request.signal, "query()/queryRoute() requests must contain an AbortController signal");
|
|
2628
2641
|
|
|
2629
2642
|
try {
|
|
2630
2643
|
if (isSubmissionMethod(request.method.toLowerCase())) {
|
|
2631
|
-
let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), routeMatch != null);
|
|
2644
|
+
let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, routeMatch != null);
|
|
2632
2645
|
return result;
|
|
2633
2646
|
}
|
|
2634
2647
|
|
|
2635
|
-
let result = await loadRouteData(request, matches, routeMatch);
|
|
2636
|
-
return result
|
|
2648
|
+
let result = await loadRouteData(request, matches, requestContext, routeMatch);
|
|
2649
|
+
return isResponse(result) ? result : _extends({}, result, {
|
|
2637
2650
|
actionData: null,
|
|
2638
2651
|
actionHeaders: {}
|
|
2639
2652
|
});
|
|
@@ -2659,7 +2672,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2659
2672
|
}
|
|
2660
2673
|
}
|
|
2661
2674
|
|
|
2662
|
-
async function submit(request, matches, actionMatch, isRouteRequest) {
|
|
2675
|
+
async function submit(request, matches, actionMatch, requestContext, isRouteRequest) {
|
|
2663
2676
|
let result;
|
|
2664
2677
|
|
|
2665
2678
|
if (!actionMatch.route.action) {
|
|
@@ -2678,7 +2691,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2678
2691
|
error
|
|
2679
2692
|
};
|
|
2680
2693
|
} else {
|
|
2681
|
-
result = await callLoaderOrAction("action", request, actionMatch, matches, basename, true, isRouteRequest);
|
|
2694
|
+
result = await callLoaderOrAction("action", request, actionMatch, matches, basename, true, isRouteRequest, requestContext);
|
|
2682
2695
|
|
|
2683
2696
|
if (request.signal.aborted) {
|
|
2684
2697
|
let method = isRouteRequest ? "queryRoute" : "query";
|
|
@@ -2729,7 +2742,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2729
2742
|
// Store off the pending error - we use it to determine which loaders
|
|
2730
2743
|
// to call and will commit it when we complete the navigation
|
|
2731
2744
|
let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
|
|
2732
|
-
let context = await loadRouteData(request, matches, undefined, {
|
|
2745
|
+
let context = await loadRouteData(request, matches, requestContext, undefined, {
|
|
2733
2746
|
[boundaryMatch.route.id]: result.error
|
|
2734
2747
|
}); // action status codes take precedence over loader status codes
|
|
2735
2748
|
|
|
@@ -2746,7 +2759,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2746
2759
|
let loaderRequest = new Request(request.url, {
|
|
2747
2760
|
signal: request.signal
|
|
2748
2761
|
});
|
|
2749
|
-
let context = await loadRouteData(loaderRequest, matches);
|
|
2762
|
+
let context = await loadRouteData(loaderRequest, matches, requestContext);
|
|
2750
2763
|
return _extends({}, context, result.statusCode ? {
|
|
2751
2764
|
statusCode: result.statusCode
|
|
2752
2765
|
} : {}, {
|
|
@@ -2759,7 +2772,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2759
2772
|
});
|
|
2760
2773
|
}
|
|
2761
2774
|
|
|
2762
|
-
async function loadRouteData(request, matches, routeMatch, pendingActionError) {
|
|
2775
|
+
async function loadRouteData(request, matches, requestContext, routeMatch, pendingActionError) {
|
|
2763
2776
|
let isRouteRequest = routeMatch != null; // Short circuit if we have no loaders to run (queryRoute())
|
|
2764
2777
|
|
|
2765
2778
|
if (isRouteRequest && !(routeMatch != null && routeMatch.route.loader)) {
|
|
@@ -2783,7 +2796,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2783
2796
|
};
|
|
2784
2797
|
}
|
|
2785
2798
|
|
|
2786
|
-
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, basename, true, isRouteRequest))]);
|
|
2799
|
+
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, basename, true, isRouteRequest, requestContext))]);
|
|
2787
2800
|
|
|
2788
2801
|
if (request.signal.aborted) {
|
|
2789
2802
|
let method = isRouteRequest ? "queryRoute" : "query";
|
|
@@ -2993,7 +3006,7 @@ function shouldRevalidateLoader(currentLocation, currentMatch, submission, locat
|
|
|
2993
3006
|
return defaultShouldRevalidate;
|
|
2994
3007
|
}
|
|
2995
3008
|
|
|
2996
|
-
async function callLoaderOrAction(type, request, match, matches, basename, isStaticRequest, isRouteRequest) {
|
|
3009
|
+
async function callLoaderOrAction(type, request, match, matches, basename, isStaticRequest, isRouteRequest, requestContext) {
|
|
2997
3010
|
if (basename === void 0) {
|
|
2998
3011
|
basename = "/";
|
|
2999
3012
|
}
|
|
@@ -3021,7 +3034,8 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
|
|
|
3021
3034
|
invariant(handler, "Could not find the " + type + " to run on the \"" + match.route.id + "\" route");
|
|
3022
3035
|
result = await Promise.race([handler({
|
|
3023
3036
|
request,
|
|
3024
|
-
params: match.params
|
|
3037
|
+
params: match.params,
|
|
3038
|
+
context: requestContext
|
|
3025
3039
|
}), abortPromise]);
|
|
3026
3040
|
invariant(result !== undefined, "You defined " + (type === "action" ? "an action" : "a loader") + " for route " + ("\"" + match.route.id + "\" but didn't return anything from your `" + type + "` ") + "function. Please return a value or `null`.");
|
|
3027
3041
|
} catch (e) {
|
|
@@ -3031,22 +3045,18 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
|
|
|
3031
3045
|
request.signal.removeEventListener("abort", onReject);
|
|
3032
3046
|
}
|
|
3033
3047
|
|
|
3034
|
-
if (result
|
|
3048
|
+
if (isResponse(result)) {
|
|
3035
3049
|
let status = result.status; // Process redirects
|
|
3036
3050
|
|
|
3037
3051
|
if (redirectStatusCodes.has(status)) {
|
|
3038
3052
|
let location = result.headers.get("Location");
|
|
3039
|
-
invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
|
|
3053
|
+
invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
|
|
3054
|
+
let isAbsolute = /^[a-z+]+:\/\//i.test(location) || location.startsWith("//"); // Support relative routing in internal redirects
|
|
3040
3055
|
|
|
3041
|
-
|
|
3042
|
-
let currentOrigin = currentUrl.origin;
|
|
3043
|
-
let newOrigin = new URL(location, currentOrigin).origin;
|
|
3044
|
-
let external = newOrigin !== currentOrigin; // Support relative routing in internal redirects
|
|
3045
|
-
|
|
3046
|
-
if (!external) {
|
|
3056
|
+
if (!isAbsolute) {
|
|
3047
3057
|
let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
|
|
3048
3058
|
let routePathnames = getPathContributingMatches(activeMatches).map(match => match.pathnameBase);
|
|
3049
|
-
let resolvedLocation = resolveTo(location, routePathnames,
|
|
3059
|
+
let resolvedLocation = resolveTo(location, routePathnames, new URL(request.url).pathname);
|
|
3050
3060
|
invariant(createPath(resolvedLocation), "Unable to resolve redirect location: " + location); // Prepend the basename to the redirect location if we have one
|
|
3051
3061
|
|
|
3052
3062
|
if (basename) {
|
|
@@ -3070,8 +3080,7 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
|
|
|
3070
3080
|
type: ResultType.redirect,
|
|
3071
3081
|
status,
|
|
3072
3082
|
location,
|
|
3073
|
-
revalidate: result.headers.get("X-Remix-Revalidate") !== null
|
|
3074
|
-
external
|
|
3083
|
+
revalidate: result.headers.get("X-Remix-Revalidate") !== null
|
|
3075
3084
|
};
|
|
3076
3085
|
} // For SSR single-route requests, we want to hand Responses back directly
|
|
3077
3086
|
// without unwrapping. We do this with the QueryRouteResponse wrapper
|
|
@@ -3318,13 +3327,12 @@ function getShortCircuitMatches(routes) {
|
|
|
3318
3327
|
};
|
|
3319
3328
|
}
|
|
3320
3329
|
|
|
3321
|
-
function getInternalRouterError(status,
|
|
3330
|
+
function getInternalRouterError(status, _temp3) {
|
|
3322
3331
|
let {
|
|
3323
3332
|
pathname,
|
|
3324
3333
|
routeId,
|
|
3325
|
-
method
|
|
3326
|
-
|
|
3327
|
-
} = _temp === void 0 ? {} : _temp;
|
|
3334
|
+
method
|
|
3335
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3328
3336
|
let statusText = "Unknown Server Error";
|
|
3329
3337
|
let errorMessage = "Unknown @remix-run/router error";
|
|
3330
3338
|
|
|
@@ -3389,8 +3397,12 @@ function isRedirectResult(result) {
|
|
|
3389
3397
|
return (result && result.type) === ResultType.redirect;
|
|
3390
3398
|
}
|
|
3391
3399
|
|
|
3400
|
+
function isResponse(value) {
|
|
3401
|
+
return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
|
3402
|
+
}
|
|
3403
|
+
|
|
3392
3404
|
function isRedirectResponse(result) {
|
|
3393
|
-
if (!(result
|
|
3405
|
+
if (!isResponse(result)) {
|
|
3394
3406
|
return false;
|
|
3395
3407
|
}
|
|
3396
3408
|
|
|
@@ -3400,7 +3412,7 @@ function isRedirectResponse(result) {
|
|
|
3400
3412
|
}
|
|
3401
3413
|
|
|
3402
3414
|
function isQueryRouteResponse(obj) {
|
|
3403
|
-
return obj && obj.response
|
|
3415
|
+
return obj && isResponse(obj.response) && (obj.type === ResultType.data || ResultType.error);
|
|
3404
3416
|
}
|
|
3405
3417
|
|
|
3406
3418
|
function isValidMethod(method) {
|