@remix-run/router 0.0.0-experimental-71108452 → 0.0.0-experimental-c7dd3d3a

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.15.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix a `future.v7_partialHydration` bug that would re-run loaders below the boundary on hydration if SSR loader errors bubbled to a parent boundary ([#11324](https://github.com/remix-run/react-router/pull/11324))
8
+ - Fix a `future.v7_partialHydration` bug that would consider the router uninitialized if a route did not have a loader ([#11325](https://github.com/remix-run/react-router/pull/11325))
9
+
3
10
  ## 1.15.2
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction, DataStrategyFunctionArgs, DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HandlerResult as unstable_HandlerResult, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
1
+ export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction as unstable_DataStrategyFunction, DataStrategyFunctionArgs as unstable_DataStrategyFunctionArgs, DataStrategyMatch as unstable_DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HandlerResult as unstable_HandlerResult, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
2
2
  export { AbortedDeferredError, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, resolvePath, resolveTo, stripBasename, } from "./utils";
3
3
  export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
4
4
  export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath, } from "./history";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-71108452
2
+ * @remix-run/router v0.0.0-experimental-c7dd3d3a
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1676,7 +1676,7 @@ function createRouter(init) {
1676
1676
  v7_partialHydration: false,
1677
1677
  v7_prependBasename: false,
1678
1678
  v7_relativeSplatPath: false,
1679
- unstable_skipActionErrorRevalidation: true
1679
+ unstable_skipActionErrorRevalidation: false
1680
1680
  }, init.future);
1681
1681
  // Cleanup function for history
1682
1682
  let unlistenHistory = null;
@@ -2371,7 +2371,8 @@ function createRouter(init) {
2371
2371
  // If the user didn't explicity indicate replace behavior, replace if
2372
2372
  // we redirected to the exact same location we're currently at to avoid
2373
2373
  // double back-buttons
2374
- replace = result.response.headers.get("Location") === state.location.pathname + state.location.search;
2374
+ let location = normalizeRedirectLocation(result.response.headers.get("Location"), new URL(request.url), basename);
2375
+ replace = location === state.location.pathname + state.location.search;
2375
2376
  }
2376
2377
  await startRedirectNavigation(request, result, {
2377
2378
  submission,
@@ -2889,22 +2890,10 @@ function createRouter(init) {
2889
2890
  }
2890
2891
  let location = redirect.response.headers.get("Location");
2891
2892
  invariant(location, "Expected a Location header on the redirect Response");
2893
+ location = normalizeRedirectLocation(location, new URL(request.url), basename);
2892
2894
  let redirectLocation = createLocation(state.location, location, {
2893
2895
  _isRedirect: true
2894
2896
  });
2895
- if (ABSOLUTE_URL_REGEX.test(location)) {
2896
- // Strip off the protocol+origin for same-origin + same-basename absolute redirects
2897
- let normalizedLocation = location;
2898
- let currentUrl = new URL(request.url);
2899
- let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
2900
- let isSameBasename = stripBasename(url.pathname, basename) != null;
2901
- if (url.origin === currentUrl.origin && isSameBasename) {
2902
- normalizedLocation = url.pathname + url.search + url.hash;
2903
- redirectLocation = createLocation(state.location, normalizedLocation, {
2904
- _isRedirect: true
2905
- });
2906
- }
2907
- }
2908
2897
  if (isBrowser) {
2909
2898
  let isDocumentReload = false;
2910
2899
  if (redirect.response.headers.has("X-Remix-Reload-Document")) {
@@ -2977,9 +2966,10 @@ function createRouter(init) {
2977
2966
  let results = await callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLoad, matches, manifest, mapRouteProperties);
2978
2967
  return await Promise.all(results.map((result, i) => {
2979
2968
  if (isRedirectHandlerResult(result)) {
2969
+ let response = result.result;
2980
2970
  return {
2981
2971
  type: ResultType.redirect,
2982
- response: normalizeRelativeRoutingRedirectResponse(result.result, request, matchesToLoad[i].route.id, matches, basename, future.v7_relativeSplatPath)
2972
+ response: normalizeRelativeRoutingRedirectResponse(response, request, matchesToLoad[i].route.id, matches, basename, future.v7_relativeSplatPath)
2983
2973
  };
2984
2974
  }
2985
2975
  return convertHandlerResultToDataResult(result);
@@ -3361,14 +3351,19 @@ function createStaticHandler(routes, opts) {
3361
3351
  * return it directly.
3362
3352
  *
3363
3353
  * - `opts.loadRouteIds` is an optional array of routeIds if you wish to only
3364
- * run a subset of route loaders on a GET request
3354
+ * run a subset of route loaders on a GET request
3365
3355
  * - `opts.requestContext` is an optional server context that will be passed
3366
- * to actions/loaders in the `context` parameter
3356
+ * to actions/loaders in the `context` parameter
3357
+ * - `opts.skipLoaderErrorBubbling` is an optional parameter that will prevent
3358
+ * the bubbling of loader errors which allows single-fetch-type implementations
3359
+ * where the client will handle the bubbling and we may need to return data
3360
+ * for the handling route
3367
3361
  */
3368
3362
  async function query(request, _temp3) {
3369
3363
  let {
3370
3364
  loadRouteIds,
3371
- requestContext
3365
+ requestContext,
3366
+ skipLoaderErrorBubbling
3372
3367
  } = _temp3 === void 0 ? {} : _temp3;
3373
3368
  let url = new URL(request.url);
3374
3369
  let method = request.method;
@@ -3421,7 +3416,7 @@ function createStaticHandler(routes, opts) {
3421
3416
  activeDeferreds: null
3422
3417
  };
3423
3418
  }
3424
- let result = await queryImpl(request, location, matches, requestContext, loadRouteIds || null, null);
3419
+ let result = await queryImpl(request, location, matches, requestContext, loadRouteIds || null, skipLoaderErrorBubbling === true, null);
3425
3420
  if (isResponse(result)) {
3426
3421
  return result;
3427
3422
  }
@@ -3493,7 +3488,7 @@ function createStaticHandler(routes, opts) {
3493
3488
  pathname: location.pathname
3494
3489
  });
3495
3490
  }
3496
- let result = await queryImpl(request, location, matches, requestContext, null, match);
3491
+ let result = await queryImpl(request, location, matches, requestContext, null, false, match);
3497
3492
  if (isResponse(result)) {
3498
3493
  return result;
3499
3494
  }
@@ -3520,14 +3515,14 @@ function createStaticHandler(routes, opts) {
3520
3515
  }
3521
3516
  return undefined;
3522
3517
  }
3523
- async function queryImpl(request, location, matches, requestContext, loadRouteIds, routeMatch) {
3518
+ async function queryImpl(request, location, matches, requestContext, loadRouteIds, skipLoaderErrorBubbling, routeMatch) {
3524
3519
  invariant(request.signal, "query()/queryRoute() requests must contain an AbortController signal");
3525
3520
  try {
3526
3521
  if (isMutationMethod(request.method.toLowerCase())) {
3527
- let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, loadRouteIds, routeMatch != null);
3522
+ let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, loadRouteIds, skipLoaderErrorBubbling, routeMatch != null);
3528
3523
  return result;
3529
3524
  }
3530
- let result = await loadRouteData(request, matches, requestContext, loadRouteIds, routeMatch);
3525
+ let result = await loadRouteData(request, matches, requestContext, loadRouteIds, skipLoaderErrorBubbling, routeMatch);
3531
3526
  return isResponse(result) ? result : _extends({}, result, {
3532
3527
  actionData: null,
3533
3528
  actionHeaders: {}
@@ -3550,7 +3545,7 @@ function createStaticHandler(routes, opts) {
3550
3545
  throw e;
3551
3546
  }
3552
3547
  }
3553
- async function submit(request, matches, actionMatch, requestContext, loadRouteIds, isRouteRequest) {
3548
+ async function submit(request, matches, actionMatch, requestContext, loadRouteIds, skipLoaderErrorBubbling, isRouteRequest) {
3554
3549
  let result;
3555
3550
  if (!actionMatch.route.action && !actionMatch.route.lazy) {
3556
3551
  let error = getInternalRouterError(405, {
@@ -3628,7 +3623,7 @@ function createStaticHandler(routes, opts) {
3628
3623
  // Store off the pending error - we use it to determine which loaders
3629
3624
  // to call and will commit it when we complete the navigation
3630
3625
  let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
3631
- let context = await loadRouteData(loaderRequest, matches, requestContext, loadRouteIds, null, [boundaryMatch.route.id, result]);
3626
+ let context = await loadRouteData(loaderRequest, matches, requestContext, loadRouteIds, skipLoaderErrorBubbling, null, [boundaryMatch.route.id, result]);
3632
3627
 
3633
3628
  // action status codes take precedence over loader status codes
3634
3629
  return _extends({}, context, {
@@ -3639,7 +3634,7 @@ function createStaticHandler(routes, opts) {
3639
3634
  } : {})
3640
3635
  });
3641
3636
  }
3642
- let context = await loadRouteData(loaderRequest, matches, requestContext, loadRouteIds, null);
3637
+ let context = await loadRouteData(loaderRequest, matches, requestContext, loadRouteIds, skipLoaderErrorBubbling, null);
3643
3638
  return _extends({}, context, {
3644
3639
  actionData: {
3645
3640
  [actionMatch.route.id]: result.data
@@ -3652,7 +3647,7 @@ function createStaticHandler(routes, opts) {
3652
3647
  } : {}
3653
3648
  });
3654
3649
  }
3655
- async function loadRouteData(request, matches, requestContext, loadRouteIds, routeMatch, pendingActionResult) {
3650
+ async function loadRouteData(request, matches, requestContext, loadRouteIds, skipLoaderErrorBubbling, routeMatch, pendingActionResult) {
3656
3651
  let isRouteRequest = routeMatch != null;
3657
3652
 
3658
3653
  // Short circuit if we have no loaders to run (queryRoute())
@@ -3692,7 +3687,7 @@ function createStaticHandler(routes, opts) {
3692
3687
 
3693
3688
  // Process and commit output from loaders
3694
3689
  let activeDeferreds = new Map();
3695
- let context = processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds);
3690
+ let context = processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds, skipLoaderErrorBubbling);
3696
3691
 
3697
3692
  // Add a null for any non-loader matches for proper revalidation on the client
3698
3693
  let executedLoaders = new Set(matchesToLoad.map(match => match.route.id));
@@ -3713,8 +3708,9 @@ function createStaticHandler(routes, opts) {
3713
3708
  let results = await callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLoad, matches, manifest, mapRouteProperties, requestContext);
3714
3709
  return await Promise.all(results.map((result, i) => {
3715
3710
  if (isRedirectHandlerResult(result)) {
3711
+ let response = result.result;
3716
3712
  // Throw redirects and let the server handle them with an HTTP redirect
3717
- throw normalizeRelativeRoutingRedirectResponse(result.result, request, matchesToLoad[i].route.id, matches, basename, future.v7_relativeSplatPath);
3713
+ throw normalizeRelativeRoutingRedirectResponse(response, request, matchesToLoad[i].route.id, matches, basename, future.v7_relativeSplatPath);
3718
3714
  }
3719
3715
  if (isResponse(result.result) && isRouteRequest) {
3720
3716
  // For SSR single-route requests, we want to hand Responses back
@@ -3956,7 +3952,8 @@ function getMatchesToLoad(history, state, matches, submission, location, isIniti
3956
3952
  // Don't revalidate loaders by default after action 4xx/5xx responses
3957
3953
  // when the flag is enabled. They can still opt-into revalidation via
3958
3954
  // `shouldRevalidate` via `actionResult`
3959
- let shouldSkipRevalidation = skipActionErrorRevalidation && pendingActionResult && typeof pendingActionResult[1].statusCode === "number" && pendingActionResult[1].statusCode >= 400;
3955
+ let actionStatus = pendingActionResult ? pendingActionResult[1].statusCode : undefined;
3956
+ let shouldSkipRevalidation = skipActionErrorRevalidation && actionStatus && actionStatus >= 400;
3960
3957
  let navigationMatches = boundaryMatches.filter((match, index) => {
3961
3958
  let {
3962
3959
  route
@@ -3995,6 +3992,7 @@ function getMatchesToLoad(history, state, matches, submission, location, isIniti
3995
3992
  nextParams: nextRouteMatch.params
3996
3993
  }, submission, {
3997
3994
  actionResult,
3995
+ unstable_actionStatus: actionStatus,
3998
3996
  defaultShouldRevalidate: shouldSkipRevalidation ? false :
3999
3997
  // Forced revalidation due to submission, useRevalidator, or X-Remix-Revalidate
4000
3998
  isRevalidationRequired || currentUrl.pathname + currentUrl.search === nextUrl.pathname + nextUrl.search ||
@@ -4059,6 +4057,7 @@ function getMatchesToLoad(history, state, matches, submission, location, isIniti
4059
4057
  nextParams: matches[matches.length - 1].params
4060
4058
  }, submission, {
4061
4059
  actionResult,
4060
+ unstable_actionStatus: actionStatus,
4062
4061
  defaultShouldRevalidate: shouldSkipRevalidation ? false : isRevalidationRequired
4063
4062
  }));
4064
4063
  }
@@ -4182,13 +4181,7 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
4182
4181
  // over the execution of the loader/action
4183
4182
  let resolve = handlerOverride => {
4184
4183
  loadedMatches.add(match.route.id);
4185
- return shouldLoad ? callLoaderOrAction(type, request, match, manifest, mapRouteProperties, handlerOverride, requestContext) :
4186
- // TODO: What's the best thing to do here - return an empty "success" result?
4187
- // Or return a success result with the current route loader/action data?
4188
- // We strip these results out if the route didn't need to be revalidated in
4189
- // `callDataStrategy` so it doesn't matter for us. It's more of a question
4190
- // of whether exposing the current data to the user is useful?
4191
- Promise.resolve({
4184
+ return shouldLoad ? callLoaderOrAction(type, request, match, manifest, mapRouteProperties, handlerOverride, requestContext) : Promise.resolve({
4192
4185
  type: ResultType.data,
4193
4186
  result: undefined
4194
4187
  });
@@ -4204,8 +4197,6 @@ async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLo
4204
4197
 
4205
4198
  // Throw if any loadRoute implementations not called since they are what
4206
4199
  // ensures a route is fully loaded
4207
- // Throw if any loadRoute implementations not called since they are what
4208
- // ensure a route is fully loaded
4209
4200
  matches.forEach(m => invariant(loadedMatches.has(m.route.id), "`match.resolve()` was not called for route id \"" + m.route.id + "\". " + "You must call `match.resolve()` on every match passed to " + "`dataStrategy` to ensure all routes are properly loaded."));
4210
4201
 
4211
4202
  // Filter out any middleware-only matches for which we didn't need to run handlers
@@ -4399,6 +4390,18 @@ function normalizeRelativeRoutingRedirectResponse(response, request, routeId, ma
4399
4390
  }
4400
4391
  return response;
4401
4392
  }
4393
+ function normalizeRedirectLocation(location, currentUrl, basename) {
4394
+ if (ABSOLUTE_URL_REGEX.test(location)) {
4395
+ // Strip off the protocol+origin for same-origin + same-basename absolute redirects
4396
+ let normalizedLocation = location;
4397
+ let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
4398
+ let isSameBasename = stripBasename(url.pathname, basename) != null;
4399
+ if (url.origin === currentUrl.origin && isSameBasename) {
4400
+ return url.pathname + url.search + url.hash;
4401
+ }
4402
+ }
4403
+ return location;
4404
+ }
4402
4405
 
4403
4406
  // Utility method for creating the Request instances for loaders/actions during
4404
4407
  // client-side navigations and fetches. During SSR we will always have a
@@ -4450,7 +4453,7 @@ function convertSearchParamsToFormData(searchParams) {
4450
4453
  }
4451
4454
  return formData;
4452
4455
  }
4453
- function processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds) {
4456
+ function processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds, skipLoaderErrorBubbling) {
4454
4457
  // Fill in loaderData/errors from our loaders
4455
4458
  let loaderData = {};
4456
4459
  let errors = null;
@@ -4464,9 +4467,6 @@ function processRouteLoaderData(matches, matchesToLoad, results, pendingActionRe
4464
4467
  let id = matchesToLoad[index].route.id;
4465
4468
  invariant(!isRedirectResult(result), "Cannot handle redirect results in processLoaderData");
4466
4469
  if (isErrorResult(result)) {
4467
- // Look upwards from the matched route for the closest ancestor
4468
- // error boundary, defaulting to the root match
4469
- let boundaryMatch = findNearestBoundary(matches, id);
4470
4470
  let error = result.error;
4471
4471
  // If we have a pending action error, we report it at the highest-route
4472
4472
  // that throws a loader error, and then clear it out to indicate that
@@ -4476,10 +4476,16 @@ function processRouteLoaderData(matches, matchesToLoad, results, pendingActionRe
4476
4476
  pendingError = undefined;
4477
4477
  }
4478
4478
  errors = errors || {};
4479
-
4480
- // Prefer higher error values if lower errors bubble to the same boundary
4481
- if (errors[boundaryMatch.route.id] == null) {
4482
- errors[boundaryMatch.route.id] = error;
4479
+ if (skipLoaderErrorBubbling) {
4480
+ errors[id] = error;
4481
+ } else {
4482
+ // Look upwards from the matched route for the closest ancestor error
4483
+ // boundary, defaulting to the root match. Prefer higher error values
4484
+ // if lower errors bubble to the same boundary
4485
+ let boundaryMatch = findNearestBoundary(matches, id);
4486
+ if (errors[boundaryMatch.route.id] == null) {
4487
+ errors[boundaryMatch.route.id] = error;
4488
+ }
4483
4489
  }
4484
4490
 
4485
4491
  // Clear our any prior loaderData for the throwing route
@@ -4540,7 +4546,8 @@ function processLoaderData(state, matches, matchesToLoad, results, pendingAction
4540
4546
  let {
4541
4547
  loaderData,
4542
4548
  errors
4543
- } = processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds);
4549
+ } = processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds, false // This method is only called client side so we always want to bubble
4550
+ );
4544
4551
 
4545
4552
  // Process results from our revalidating fetchers
4546
4553
  for (let index = 0; index < revalidatingFetchers.length; index++) {