@remix-run/router 1.0.5-pre.1 → 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 +7 -0
- package/dist/router.cjs.js +27 -20
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +7 -2
- package/dist/router.js +27 -20
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +27 -20
- 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 -0
- package/package.json +1 -1
- package/router.ts +52 -17
- package/utils.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
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
|
+
|
|
3
10
|
## 1.0.5-pre.1
|
|
4
11
|
|
|
5
12
|
### 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
|
*
|
|
@@ -2492,7 +2492,10 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2492
2492
|
* return it directly.
|
|
2493
2493
|
*/
|
|
2494
2494
|
|
|
2495
|
-
async function query(request) {
|
|
2495
|
+
async function query(request, _temp) {
|
|
2496
|
+
let {
|
|
2497
|
+
requestContext
|
|
2498
|
+
} = _temp === void 0 ? {} : _temp;
|
|
2496
2499
|
let url = new URL(request.url);
|
|
2497
2500
|
let method = request.method.toLowerCase();
|
|
2498
2501
|
let location = createLocation("", createPath(url), null, "default");
|
|
@@ -2542,7 +2545,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2542
2545
|
};
|
|
2543
2546
|
}
|
|
2544
2547
|
|
|
2545
|
-
let result = await queryImpl(request, location, matches);
|
|
2548
|
+
let result = await queryImpl(request, location, matches, requestContext);
|
|
2546
2549
|
|
|
2547
2550
|
if (isResponse(result)) {
|
|
2548
2551
|
return result;
|
|
@@ -2578,7 +2581,11 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2578
2581
|
*/
|
|
2579
2582
|
|
|
2580
2583
|
|
|
2581
|
-
async function queryRoute(request,
|
|
2584
|
+
async function queryRoute(request, _temp2) {
|
|
2585
|
+
let {
|
|
2586
|
+
routeId,
|
|
2587
|
+
requestContext
|
|
2588
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2582
2589
|
let url = new URL(request.url);
|
|
2583
2590
|
let method = request.method.toLowerCase();
|
|
2584
2591
|
let location = createLocation("", createPath(url), null, "default");
|
|
@@ -2608,7 +2615,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2608
2615
|
});
|
|
2609
2616
|
}
|
|
2610
2617
|
|
|
2611
|
-
let result = await queryImpl(request, location, matches, match);
|
|
2618
|
+
let result = await queryImpl(request, location, matches, requestContext, match);
|
|
2612
2619
|
|
|
2613
2620
|
if (isResponse(result)) {
|
|
2614
2621
|
return result;
|
|
@@ -2629,16 +2636,16 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2629
2636
|
return Object.values(routeData || {})[0];
|
|
2630
2637
|
}
|
|
2631
2638
|
|
|
2632
|
-
async function queryImpl(request, location, matches, routeMatch) {
|
|
2639
|
+
async function queryImpl(request, location, matches, requestContext, routeMatch) {
|
|
2633
2640
|
invariant(request.signal, "query()/queryRoute() requests must contain an AbortController signal");
|
|
2634
2641
|
|
|
2635
2642
|
try {
|
|
2636
2643
|
if (isSubmissionMethod(request.method.toLowerCase())) {
|
|
2637
|
-
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);
|
|
2638
2645
|
return result;
|
|
2639
2646
|
}
|
|
2640
2647
|
|
|
2641
|
-
let result = await loadRouteData(request, matches, routeMatch);
|
|
2648
|
+
let result = await loadRouteData(request, matches, requestContext, routeMatch);
|
|
2642
2649
|
return isResponse(result) ? result : _extends({}, result, {
|
|
2643
2650
|
actionData: null,
|
|
2644
2651
|
actionHeaders: {}
|
|
@@ -2665,7 +2672,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2665
2672
|
}
|
|
2666
2673
|
}
|
|
2667
2674
|
|
|
2668
|
-
async function submit(request, matches, actionMatch, isRouteRequest) {
|
|
2675
|
+
async function submit(request, matches, actionMatch, requestContext, isRouteRequest) {
|
|
2669
2676
|
let result;
|
|
2670
2677
|
|
|
2671
2678
|
if (!actionMatch.route.action) {
|
|
@@ -2684,7 +2691,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2684
2691
|
error
|
|
2685
2692
|
};
|
|
2686
2693
|
} else {
|
|
2687
|
-
result = await callLoaderOrAction("action", request, actionMatch, matches, basename, true, isRouteRequest);
|
|
2694
|
+
result = await callLoaderOrAction("action", request, actionMatch, matches, basename, true, isRouteRequest, requestContext);
|
|
2688
2695
|
|
|
2689
2696
|
if (request.signal.aborted) {
|
|
2690
2697
|
let method = isRouteRequest ? "queryRoute" : "query";
|
|
@@ -2735,7 +2742,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2735
2742
|
// Store off the pending error - we use it to determine which loaders
|
|
2736
2743
|
// to call and will commit it when we complete the navigation
|
|
2737
2744
|
let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
|
|
2738
|
-
let context = await loadRouteData(request, matches, undefined, {
|
|
2745
|
+
let context = await loadRouteData(request, matches, requestContext, undefined, {
|
|
2739
2746
|
[boundaryMatch.route.id]: result.error
|
|
2740
2747
|
}); // action status codes take precedence over loader status codes
|
|
2741
2748
|
|
|
@@ -2752,7 +2759,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2752
2759
|
let loaderRequest = new Request(request.url, {
|
|
2753
2760
|
signal: request.signal
|
|
2754
2761
|
});
|
|
2755
|
-
let context = await loadRouteData(loaderRequest, matches);
|
|
2762
|
+
let context = await loadRouteData(loaderRequest, matches, requestContext);
|
|
2756
2763
|
return _extends({}, context, result.statusCode ? {
|
|
2757
2764
|
statusCode: result.statusCode
|
|
2758
2765
|
} : {}, {
|
|
@@ -2765,7 +2772,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2765
2772
|
});
|
|
2766
2773
|
}
|
|
2767
2774
|
|
|
2768
|
-
async function loadRouteData(request, matches, routeMatch, pendingActionError) {
|
|
2775
|
+
async function loadRouteData(request, matches, requestContext, routeMatch, pendingActionError) {
|
|
2769
2776
|
let isRouteRequest = routeMatch != null; // Short circuit if we have no loaders to run (queryRoute())
|
|
2770
2777
|
|
|
2771
2778
|
if (isRouteRequest && !(routeMatch != null && routeMatch.route.loader)) {
|
|
@@ -2789,7 +2796,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2789
2796
|
};
|
|
2790
2797
|
}
|
|
2791
2798
|
|
|
2792
|
-
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))]);
|
|
2793
2800
|
|
|
2794
2801
|
if (request.signal.aborted) {
|
|
2795
2802
|
let method = isRouteRequest ? "queryRoute" : "query";
|
|
@@ -2999,7 +3006,7 @@ function shouldRevalidateLoader(currentLocation, currentMatch, submission, locat
|
|
|
2999
3006
|
return defaultShouldRevalidate;
|
|
3000
3007
|
}
|
|
3001
3008
|
|
|
3002
|
-
async function callLoaderOrAction(type, request, match, matches, basename, isStaticRequest, isRouteRequest) {
|
|
3009
|
+
async function callLoaderOrAction(type, request, match, matches, basename, isStaticRequest, isRouteRequest, requestContext) {
|
|
3003
3010
|
if (basename === void 0) {
|
|
3004
3011
|
basename = "/";
|
|
3005
3012
|
}
|
|
@@ -3027,7 +3034,8 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
|
|
|
3027
3034
|
invariant(handler, "Could not find the " + type + " to run on the \"" + match.route.id + "\" route");
|
|
3028
3035
|
result = await Promise.race([handler({
|
|
3029
3036
|
request,
|
|
3030
|
-
params: match.params
|
|
3037
|
+
params: match.params,
|
|
3038
|
+
context: requestContext
|
|
3031
3039
|
}), abortPromise]);
|
|
3032
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`.");
|
|
3033
3041
|
} catch (e) {
|
|
@@ -3319,13 +3327,12 @@ function getShortCircuitMatches(routes) {
|
|
|
3319
3327
|
};
|
|
3320
3328
|
}
|
|
3321
3329
|
|
|
3322
|
-
function getInternalRouterError(status,
|
|
3330
|
+
function getInternalRouterError(status, _temp3) {
|
|
3323
3331
|
let {
|
|
3324
3332
|
pathname,
|
|
3325
3333
|
routeId,
|
|
3326
|
-
method
|
|
3327
|
-
|
|
3328
|
-
} = _temp === void 0 ? {} : _temp;
|
|
3334
|
+
method
|
|
3335
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3329
3336
|
let statusText = "Unknown Server Error";
|
|
3330
3337
|
let errorMessage = "Unknown @remix-run/router error";
|
|
3331
3338
|
|