@remix-run/router 0.0.0-experimental-a0888892 → 0.0.0-experimental-acfea932

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-a0888892
2
+ * @remix-run/router v0.0.0-experimental-acfea932
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -3328,9 +3328,15 @@ function createStaticHandler(routes, opts) {
3328
3328
  * redirect response is returned or thrown from any action/loader. We
3329
3329
  * propagate that out and return the raw Response so the HTTP server can
3330
3330
  * return it directly.
3331
+ *
3332
+ * - `opts.loadRouteIds` is an optional array of routeIds if you wish to only
3333
+ * run a subset of route loaders on a GET request
3334
+ * - `opts.requestContext` is an optional server context that will be passed
3335
+ * to actions/loaders in the `context` parameter
3331
3336
  */
3332
3337
  async function query(request, _temp3) {
3333
3338
  let {
3339
+ loadRouteIds,
3334
3340
  requestContext
3335
3341
  } = _temp3 === void 0 ? {} : _temp3;
3336
3342
  let url = new URL(request.url);
@@ -3384,7 +3390,7 @@ function createStaticHandler(routes, opts) {
3384
3390
  activeDeferreds: null
3385
3391
  };
3386
3392
  }
3387
- let result = await queryImpl(request, location, matches, requestContext);
3393
+ let result = await queryImpl(request, location, matches, requestContext, loadRouteIds || null, null);
3388
3394
  if (isResponse(result)) {
3389
3395
  return result;
3390
3396
  }
@@ -3417,6 +3423,12 @@ function createStaticHandler(routes, opts) {
3417
3423
  * serialize the error as they see fit while including the proper response
3418
3424
  * code. Examples here are 404 and 405 errors that occur prior to reaching
3419
3425
  * any user-defined loaders.
3426
+ *
3427
+ * - `opts.routeId` allows you to specify the specific route handler to call.
3428
+ * If not provided the handler will determine the proper route by matching
3429
+ * against `request.url`
3430
+ * - `opts.requestContext` is an optional server context that will be passed
3431
+ * to actions/loaders in the `context` parameter
3420
3432
  */
3421
3433
  async function queryRoute(request, _temp4) {
3422
3434
  let {
@@ -3450,7 +3462,7 @@ function createStaticHandler(routes, opts) {
3450
3462
  pathname: location.pathname
3451
3463
  });
3452
3464
  }
3453
- let result = await queryImpl(request, location, matches, requestContext, match);
3465
+ let result = await queryImpl(request, location, matches, requestContext, null, match);
3454
3466
  if (isResponse(result)) {
3455
3467
  return result;
3456
3468
  }
@@ -3477,14 +3489,14 @@ function createStaticHandler(routes, opts) {
3477
3489
  }
3478
3490
  return undefined;
3479
3491
  }
3480
- async function queryImpl(request, location, matches, requestContext, routeMatch) {
3492
+ async function queryImpl(request, location, matches, requestContext, loadRouteIds, routeMatch) {
3481
3493
  invariant(request.signal, "query()/queryRoute() requests must contain an AbortController signal");
3482
3494
  try {
3483
3495
  if (isMutationMethod(request.method.toLowerCase())) {
3484
- let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, routeMatch != null);
3496
+ let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, loadRouteIds, routeMatch != null);
3485
3497
  return result;
3486
3498
  }
3487
- let result = await loadRouteData(request, matches, requestContext, routeMatch);
3499
+ let result = await loadRouteData(request, matches, requestContext, loadRouteIds, routeMatch);
3488
3500
  return isResponse(result) ? result : _extends({}, result, {
3489
3501
  actionData: null,
3490
3502
  actionHeaders: {}
@@ -3507,7 +3519,7 @@ function createStaticHandler(routes, opts) {
3507
3519
  throw e;
3508
3520
  }
3509
3521
  }
3510
- async function submit(request, matches, actionMatch, requestContext, isRouteRequest) {
3522
+ async function submit(request, matches, actionMatch, requestContext, loadRouteIds, isRouteRequest) {
3511
3523
  let result;
3512
3524
  if (!actionMatch.route.action && !actionMatch.route.lazy) {
3513
3525
  let error = getInternalRouterError(405, {
@@ -3574,11 +3586,18 @@ function createStaticHandler(routes, opts) {
3574
3586
  activeDeferreds: null
3575
3587
  };
3576
3588
  }
3589
+
3590
+ // Create a GET request for the loaders
3591
+ let loaderRequest = new Request(request.url, {
3592
+ headers: request.headers,
3593
+ redirect: request.redirect,
3594
+ signal: request.signal
3595
+ });
3577
3596
  if (isErrorResult(result)) {
3578
3597
  // Store off the pending error - we use it to determine which loaders
3579
3598
  // to call and will commit it when we complete the navigation
3580
3599
  let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
3581
- let context = await loadRouteData(request, matches, requestContext, undefined, {
3600
+ let context = await loadRouteData(loaderRequest, matches, requestContext, loadRouteIds, null, {
3582
3601
  [boundaryMatch.route.id]: result.error
3583
3602
  });
3584
3603
 
@@ -3591,14 +3610,7 @@ function createStaticHandler(routes, opts) {
3591
3610
  } : {})
3592
3611
  });
3593
3612
  }
3594
-
3595
- // Create a GET request for the loaders
3596
- let loaderRequest = new Request(request.url, {
3597
- headers: request.headers,
3598
- redirect: request.redirect,
3599
- signal: request.signal
3600
- });
3601
- let context = await loadRouteData(loaderRequest, matches, requestContext);
3613
+ let context = await loadRouteData(loaderRequest, matches, requestContext, loadRouteIds, null);
3602
3614
  return _extends({}, context, {
3603
3615
  actionData: {
3604
3616
  [actionMatch.route.id]: result.data
@@ -3612,7 +3624,7 @@ function createStaticHandler(routes, opts) {
3612
3624
  actionHeaders: {}
3613
3625
  });
3614
3626
  }
3615
- async function loadRouteData(request, matches, requestContext, routeMatch, pendingActionError) {
3627
+ async function loadRouteData(request, matches, requestContext, loadRouteIds, routeMatch, pendingActionError) {
3616
3628
  let isRouteRequest = routeMatch != null;
3617
3629
 
3618
3630
  // Short circuit if we have no loaders to run (queryRoute())
@@ -3625,6 +3637,9 @@ function createStaticHandler(routes, opts) {
3625
3637
  }
3626
3638
  let requestMatches = routeMatch ? [routeMatch] : getLoaderMatchesUntilBoundary(matches, Object.keys(pendingActionError || {})[0]);
3627
3639
  let matchesToLoad = requestMatches.filter(m => m.route.loader || m.route.lazy);
3640
+ if (loadRouteIds) {
3641
+ matchesToLoad = matchesToLoad.filter(m => loadRouteIds.includes(m.route.id));
3642
+ }
3628
3643
 
3629
3644
  // Short circuit if we have no loaders to run (query())
3630
3645
  if (matchesToLoad.length === 0) {
@@ -4129,13 +4144,14 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
4129
4144
  // back out below.
4130
4145
  let results = await dataStrategyImpl({
4131
4146
  matches: matches.map(match => {
4147
+ let bikeshed_load = routeIdsToLoad.has(match.route.id);
4132
4148
  // `bikeshed_loadRoute` encapsulates the route.lazy, executing the
4133
4149
  // loader/action, and mapping return values/thrown errors to a
4134
4150
  // HandlerResult. Users can pass a callback to take fine-grained control
4135
4151
  // over the execution of the loader/action
4136
4152
  let bikeshed_loadRoute = handlerOverride => {
4137
4153
  loadedMatches.add(match.route.id);
4138
- return routeIdsToLoad.has(match.route.id) ? callLoaderOrAction(type, request, match, manifest, mapRouteProperties, handlerOverride, requestContext) :
4154
+ return bikeshed_load ? callLoaderOrAction(type, request, match, manifest, mapRouteProperties, handlerOverride, requestContext) :
4139
4155
  // TODO: What's the best thing to do here - return an empty "success" result?
4140
4156
  // Or return a success result with the current route loader/action data?
4141
4157
  // We strip these results out if the route didn't need to be revalidated in
@@ -4147,6 +4163,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
4147
4163
  });
4148
4164
  };
4149
4165
  return _extends({}, match, {
4166
+ bikeshed_load,
4150
4167
  bikeshed_loadRoute
4151
4168
  });
4152
4169
  }),