@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/dist/router.d.ts
CHANGED
|
@@ -236,8 +236,13 @@ export interface StaticHandlerContext {
|
|
|
236
236
|
*/
|
|
237
237
|
export interface StaticHandler {
|
|
238
238
|
dataRoutes: AgnosticDataRouteObject[];
|
|
239
|
-
query(request: Request
|
|
240
|
-
|
|
239
|
+
query(request: Request, opts?: {
|
|
240
|
+
requestContext?: unknown;
|
|
241
|
+
}): Promise<StaticHandlerContext | Response>;
|
|
242
|
+
queryRoute(request: Request, opts?: {
|
|
243
|
+
routeId?: string;
|
|
244
|
+
requestContext?: unknown;
|
|
245
|
+
}): Promise<any>;
|
|
241
246
|
}
|
|
242
247
|
/**
|
|
243
248
|
* Subscriber function signature for changes to router state
|
package/dist/router.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
|
*
|
|
@@ -2444,7 +2444,10 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2444
2444
|
* return it directly.
|
|
2445
2445
|
*/
|
|
2446
2446
|
|
|
2447
|
-
async function query(request) {
|
|
2447
|
+
async function query(request, _temp) {
|
|
2448
|
+
let {
|
|
2449
|
+
requestContext
|
|
2450
|
+
} = _temp === void 0 ? {} : _temp;
|
|
2448
2451
|
let url = new URL(request.url);
|
|
2449
2452
|
let method = request.method.toLowerCase();
|
|
2450
2453
|
let location = createLocation("", createPath(url), null, "default");
|
|
@@ -2494,7 +2497,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2494
2497
|
};
|
|
2495
2498
|
}
|
|
2496
2499
|
|
|
2497
|
-
let result = await queryImpl(request, location, matches);
|
|
2500
|
+
let result = await queryImpl(request, location, matches, requestContext);
|
|
2498
2501
|
|
|
2499
2502
|
if (isResponse(result)) {
|
|
2500
2503
|
return result;
|
|
@@ -2530,7 +2533,11 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2530
2533
|
*/
|
|
2531
2534
|
|
|
2532
2535
|
|
|
2533
|
-
async function queryRoute(request,
|
|
2536
|
+
async function queryRoute(request, _temp2) {
|
|
2537
|
+
let {
|
|
2538
|
+
routeId,
|
|
2539
|
+
requestContext
|
|
2540
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2534
2541
|
let url = new URL(request.url);
|
|
2535
2542
|
let method = request.method.toLowerCase();
|
|
2536
2543
|
let location = createLocation("", createPath(url), null, "default");
|
|
@@ -2560,7 +2567,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2560
2567
|
});
|
|
2561
2568
|
}
|
|
2562
2569
|
|
|
2563
|
-
let result = await queryImpl(request, location, matches, match);
|
|
2570
|
+
let result = await queryImpl(request, location, matches, requestContext, match);
|
|
2564
2571
|
|
|
2565
2572
|
if (isResponse(result)) {
|
|
2566
2573
|
return result;
|
|
@@ -2581,16 +2588,16 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2581
2588
|
return Object.values(routeData || {})[0];
|
|
2582
2589
|
}
|
|
2583
2590
|
|
|
2584
|
-
async function queryImpl(request, location, matches, routeMatch) {
|
|
2591
|
+
async function queryImpl(request, location, matches, requestContext, routeMatch) {
|
|
2585
2592
|
invariant(request.signal, "query()/queryRoute() requests must contain an AbortController signal");
|
|
2586
2593
|
|
|
2587
2594
|
try {
|
|
2588
2595
|
if (isSubmissionMethod(request.method.toLowerCase())) {
|
|
2589
|
-
let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), routeMatch != null);
|
|
2596
|
+
let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, routeMatch != null);
|
|
2590
2597
|
return result;
|
|
2591
2598
|
}
|
|
2592
2599
|
|
|
2593
|
-
let result = await loadRouteData(request, matches, routeMatch);
|
|
2600
|
+
let result = await loadRouteData(request, matches, requestContext, routeMatch);
|
|
2594
2601
|
return isResponse(result) ? result : _extends({}, result, {
|
|
2595
2602
|
actionData: null,
|
|
2596
2603
|
actionHeaders: {}
|
|
@@ -2617,7 +2624,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2617
2624
|
}
|
|
2618
2625
|
}
|
|
2619
2626
|
|
|
2620
|
-
async function submit(request, matches, actionMatch, isRouteRequest) {
|
|
2627
|
+
async function submit(request, matches, actionMatch, requestContext, isRouteRequest) {
|
|
2621
2628
|
let result;
|
|
2622
2629
|
|
|
2623
2630
|
if (!actionMatch.route.action) {
|
|
@@ -2636,7 +2643,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2636
2643
|
error
|
|
2637
2644
|
};
|
|
2638
2645
|
} else {
|
|
2639
|
-
result = await callLoaderOrAction("action", request, actionMatch, matches, basename, true, isRouteRequest);
|
|
2646
|
+
result = await callLoaderOrAction("action", request, actionMatch, matches, basename, true, isRouteRequest, requestContext);
|
|
2640
2647
|
|
|
2641
2648
|
if (request.signal.aborted) {
|
|
2642
2649
|
let method = isRouteRequest ? "queryRoute" : "query";
|
|
@@ -2687,7 +2694,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2687
2694
|
// Store off the pending error - we use it to determine which loaders
|
|
2688
2695
|
// to call and will commit it when we complete the navigation
|
|
2689
2696
|
let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
|
|
2690
|
-
let context = await loadRouteData(request, matches, undefined, {
|
|
2697
|
+
let context = await loadRouteData(request, matches, requestContext, undefined, {
|
|
2691
2698
|
[boundaryMatch.route.id]: result.error
|
|
2692
2699
|
}); // action status codes take precedence over loader status codes
|
|
2693
2700
|
|
|
@@ -2704,7 +2711,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2704
2711
|
let loaderRequest = new Request(request.url, {
|
|
2705
2712
|
signal: request.signal
|
|
2706
2713
|
});
|
|
2707
|
-
let context = await loadRouteData(loaderRequest, matches);
|
|
2714
|
+
let context = await loadRouteData(loaderRequest, matches, requestContext);
|
|
2708
2715
|
return _extends({}, context, result.statusCode ? {
|
|
2709
2716
|
statusCode: result.statusCode
|
|
2710
2717
|
} : {}, {
|
|
@@ -2717,7 +2724,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2717
2724
|
});
|
|
2718
2725
|
}
|
|
2719
2726
|
|
|
2720
|
-
async function loadRouteData(request, matches, routeMatch, pendingActionError) {
|
|
2727
|
+
async function loadRouteData(request, matches, requestContext, routeMatch, pendingActionError) {
|
|
2721
2728
|
let isRouteRequest = routeMatch != null; // Short circuit if we have no loaders to run (queryRoute())
|
|
2722
2729
|
|
|
2723
2730
|
if (isRouteRequest && !(routeMatch != null && routeMatch.route.loader)) {
|
|
@@ -2741,7 +2748,7 @@ function unstable_createStaticHandler(routes, opts) {
|
|
|
2741
2748
|
};
|
|
2742
2749
|
}
|
|
2743
2750
|
|
|
2744
|
-
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, basename, true, isRouteRequest))]);
|
|
2751
|
+
let results = await Promise.all([...matchesToLoad.map(match => callLoaderOrAction("loader", request, match, matches, basename, true, isRouteRequest, requestContext))]);
|
|
2745
2752
|
|
|
2746
2753
|
if (request.signal.aborted) {
|
|
2747
2754
|
let method = isRouteRequest ? "queryRoute" : "query";
|
|
@@ -2951,7 +2958,7 @@ function shouldRevalidateLoader(currentLocation, currentMatch, submission, locat
|
|
|
2951
2958
|
return defaultShouldRevalidate;
|
|
2952
2959
|
}
|
|
2953
2960
|
|
|
2954
|
-
async function callLoaderOrAction(type, request, match, matches, basename, isStaticRequest, isRouteRequest) {
|
|
2961
|
+
async function callLoaderOrAction(type, request, match, matches, basename, isStaticRequest, isRouteRequest, requestContext) {
|
|
2955
2962
|
if (basename === void 0) {
|
|
2956
2963
|
basename = "/";
|
|
2957
2964
|
}
|
|
@@ -2979,7 +2986,8 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
|
|
|
2979
2986
|
invariant(handler, "Could not find the " + type + " to run on the \"" + match.route.id + "\" route");
|
|
2980
2987
|
result = await Promise.race([handler({
|
|
2981
2988
|
request,
|
|
2982
|
-
params: match.params
|
|
2989
|
+
params: match.params,
|
|
2990
|
+
context: requestContext
|
|
2983
2991
|
}), abortPromise]);
|
|
2984
2992
|
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`.");
|
|
2985
2993
|
} catch (e) {
|
|
@@ -3271,13 +3279,12 @@ function getShortCircuitMatches(routes) {
|
|
|
3271
3279
|
};
|
|
3272
3280
|
}
|
|
3273
3281
|
|
|
3274
|
-
function getInternalRouterError(status,
|
|
3282
|
+
function getInternalRouterError(status, _temp3) {
|
|
3275
3283
|
let {
|
|
3276
3284
|
pathname,
|
|
3277
3285
|
routeId,
|
|
3278
|
-
method
|
|
3279
|
-
|
|
3280
|
-
} = _temp === void 0 ? {} : _temp;
|
|
3286
|
+
method
|
|
3287
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3281
3288
|
let statusText = "Unknown Server Error";
|
|
3282
3289
|
let errorMessage = "Unknown @remix-run/router error";
|
|
3283
3290
|
|