@remix-run/router 0.0.0-experimental-de419c3d → 0.0.0-experimental-432fcb2e

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,17 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.15.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Preserve hydrated errors during partial hydration runs ([#11305](https://github.com/remix-run/react-router/pull/11305))
8
+
9
+ ## 1.15.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Fix encoding/decoding issues with pre-encoded dynamic parameter values ([#11199](https://github.com/remix-run/react-router/pull/11199))
14
+
3
15
  ## 1.15.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction, DataStrategyFunctionArgs, DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
2
- export { AbortedDeferredError, DecodedResponse, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, resolvePath, resolveTo, stripBasename, } from "./utils";
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";
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";
5
5
  export * from "./router";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-de419c3d
2
+ * @remix-run/router v0.0.0-experimental-432fcb2e
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1519,22 +1519,6 @@ class ErrorResponseImpl {
1519
1519
  }
1520
1520
  }
1521
1521
 
1522
- /**
1523
- * Utility class we use to hold unwrapped Responses while preserving status
1524
- * codes and headers. This is most useful for dataStrategy implementations
1525
- * where implementors want to use a custom decoding mechanism and return
1526
- * pre-decoded data while also preserving response meta information
1527
- */
1528
- class DecodedResponse {
1529
- constructor(status, statusText, headers, data) {
1530
- this._isDecodedResponse = true;
1531
- this.status = status;
1532
- this.statusText = statusText;
1533
- this.headers = headers;
1534
- this.data = data;
1535
- }
1536
- }
1537
-
1538
1522
  /**
1539
1523
  * Check if the given error is an ErrorResponse generated from a 4xx/5xx
1540
1524
  * Response thrown from an action/loader
@@ -1543,13 +1527,6 @@ function isRouteErrorResponse(error) {
1543
1527
  return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
1544
1528
  }
1545
1529
 
1546
- /**
1547
- * Check if the given error is an DecodedResponse
1548
- */
1549
- function isDecodedResponse(value) {
1550
- return value != null && value._isDecodedResponse === true && typeof value.status === "number" && typeof value.statusText === "string" && value.headers != null && "data" in value;
1551
- }
1552
-
1553
1530
  ////////////////////////////////////////////////////////////////////////////////
1554
1531
  //#region Types and Constants
1555
1532
  ////////////////////////////////////////////////////////////////////////////////
@@ -2454,7 +2431,7 @@ function createRouter(init) {
2454
2431
  // preserving any new action data or existing action data (in the case of
2455
2432
  // a revalidation interrupting an actionReload)
2456
2433
  // If we have partialHydration enabled, then don't update the state for the
2457
- // initial data load since iot's not a "navigation"
2434
+ // initial data load since it's not a "navigation"
2458
2435
  if (!isUninterruptedRevalidation && (!future.v7_partialHydration || !initialHydration)) {
2459
2436
  revalidatingFetchers.forEach(rf => {
2460
2437
  let fetcher = state.fetchers.get(rf.key);
@@ -2556,6 +2533,19 @@ function createRouter(init) {
2556
2533
  }
2557
2534
  });
2558
2535
  });
2536
+
2537
+ // During partial hydration, preserve SSR errors for routes that don't re-run
2538
+ if (future.v7_partialHydration && initialHydration && state.errors) {
2539
+ Object.entries(state.errors).filter(_ref2 => {
2540
+ let [id] = _ref2;
2541
+ return !matchesToLoad.some(m => m.route.id === id);
2542
+ }).forEach(_ref3 => {
2543
+ let [routeId, error] = _ref3;
2544
+ errors = Object.assign(errors || {}, {
2545
+ [routeId]: error
2546
+ });
2547
+ });
2548
+ }
2559
2549
  let updatedFetchers = markFetchRedirectsDone();
2560
2550
  let didAbortFetchLoads = abortStaleFetchLoads(pendingNavigationLoadId);
2561
2551
  let shouldUpdateFetchers = updatedFetchers || didAbortFetchLoads || revalidatingFetchers.length > 0;
@@ -3156,12 +3146,12 @@ function createRouter(init) {
3156
3146
  blockers
3157
3147
  });
3158
3148
  }
3159
- function shouldBlockNavigation(_ref2) {
3149
+ function shouldBlockNavigation(_ref4) {
3160
3150
  let {
3161
3151
  currentLocation,
3162
3152
  nextLocation,
3163
3153
  historyAction
3164
- } = _ref2;
3154
+ } = _ref4;
3165
3155
  if (blockerFunctions.size === 0) {
3166
3156
  return;
3167
3157
  }
@@ -3832,8 +3822,8 @@ function normalizeNavigateOptions(normalizeFormMethod, isFetcher, path, opts) {
3832
3822
  }
3833
3823
  let text = typeof opts.body === "string" ? opts.body : opts.body instanceof FormData || opts.body instanceof URLSearchParams ?
3834
3824
  // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plain-text-form-data
3835
- Array.from(opts.body.entries()).reduce((acc, _ref3) => {
3836
- let [name, value] = _ref3;
3825
+ Array.from(opts.body.entries()).reduce((acc, _ref5) => {
3826
+ let [name, value] = _ref5;
3837
3827
  return "" + acc + name + "=" + value + "\n";
3838
3828
  }, "") : String(opts.body);
3839
3829
  return {
@@ -4210,10 +4200,12 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
4210
4200
  let runHandler = handler => {
4211
4201
  // Setup a promise we can race against so that abort signals short circuit
4212
4202
  let reject;
4203
+ // This will never resolve so safe to type it as Promise<HandlerResult> to
4204
+ // satisfy the function return value
4213
4205
  let abortPromise = new Promise((_, r) => reject = r);
4214
4206
  onReject = () => reject();
4215
4207
  request.signal.addEventListener("abort", onReject);
4216
- let runHandlerForReal = ctx => {
4208
+ let actualHandler = ctx => {
4217
4209
  if (typeof handler !== "function") {
4218
4210
  return Promise.reject(new Error("You cannot call the handler for a route which defines a boolean " + ("\"" + type + "\" [routeId: " + match.route.id + "]")));
4219
4211
  }
@@ -4223,7 +4215,25 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
4223
4215
  context: staticContext
4224
4216
  }, ...(ctx !== undefined ? [ctx] : []));
4225
4217
  };
4226
- let handlerPromise = handlerOverride ? handlerOverride(async ctx => runHandlerForReal(ctx)) : runHandlerForReal();
4218
+ let handlerPromise;
4219
+ if (handlerOverride) {
4220
+ handlerPromise = handlerOverride(ctx => actualHandler(ctx));
4221
+ } else {
4222
+ handlerPromise = (async () => {
4223
+ try {
4224
+ let val = await actualHandler();
4225
+ return {
4226
+ type: "data",
4227
+ result: val
4228
+ };
4229
+ } catch (e) {
4230
+ return {
4231
+ type: "error",
4232
+ result: e
4233
+ };
4234
+ }
4235
+ })();
4236
+ }
4227
4237
  return Promise.race([handlerPromise, abortPromise]);
4228
4238
  };
4229
4239
  try {
@@ -4278,8 +4288,11 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
4278
4288
  } else {
4279
4289
  result = await runHandler(handler);
4280
4290
  }
4281
- 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`.");
4291
+ invariant(result.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`.");
4282
4292
  } catch (e) {
4293
+ // We should already be catching and converting normal handler executions to
4294
+ // HandlerResults and returning them, so anything that throws here is an
4295
+ // unexpected error we still need to wrap
4283
4296
  return {
4284
4297
  type: ResultType.error,
4285
4298
  result: e
@@ -4289,15 +4302,13 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
4289
4302
  request.signal.removeEventListener("abort", onReject);
4290
4303
  }
4291
4304
  }
4292
- return {
4293
- type: ResultType.data,
4294
- result
4295
- };
4305
+ return result;
4296
4306
  }
4297
4307
  async function convertHandlerResultToDataResult(handlerResult) {
4298
4308
  let {
4299
4309
  result,
4300
- type
4310
+ type,
4311
+ status
4301
4312
  } = handlerResult;
4302
4313
  if (isResponse(result)) {
4303
4314
  let data;
@@ -4322,7 +4333,7 @@ async function convertHandlerResultToDataResult(handlerResult) {
4322
4333
  }
4323
4334
  if (type === ResultType.error) {
4324
4335
  return {
4325
- type,
4336
+ type: ResultType.error,
4326
4337
  error: new ErrorResponseImpl(result.status, result.statusText, data),
4327
4338
  statusCode: result.status,
4328
4339
  headers: result.headers
@@ -4335,27 +4346,11 @@ async function convertHandlerResultToDataResult(handlerResult) {
4335
4346
  headers: result.headers
4336
4347
  };
4337
4348
  }
4338
- if (isDecodedResponse(result)) {
4339
- if (type === ResultType.error) {
4340
- return {
4341
- type,
4342
- error: new ErrorResponseImpl(result.status, result.statusText, result.data),
4343
- statusCode: result.status,
4344
- headers: result.headers
4345
- };
4346
- }
4347
- return {
4348
- type: ResultType.data,
4349
- data: result.data,
4350
- statusCode: result.status,
4351
- headers: result.headers
4352
- };
4353
- }
4354
4349
  if (type === ResultType.error) {
4355
4350
  return {
4356
- type,
4351
+ type: ResultType.error,
4357
4352
  error: result,
4358
- statusCode: isRouteErrorResponse(result) ? result.status : undefined
4353
+ statusCode: isRouteErrorResponse(result) ? result.status : status
4359
4354
  };
4360
4355
  }
4361
4356
  if (isDeferredData(result)) {
@@ -4369,7 +4364,8 @@ async function convertHandlerResultToDataResult(handlerResult) {
4369
4364
  }
4370
4365
  return {
4371
4366
  type: ResultType.data,
4372
- data: result
4367
+ data: result,
4368
+ statusCode: status
4373
4369
  };
4374
4370
  }
4375
4371
 
@@ -4965,7 +4961,6 @@ function persistAppliedTransitions(_window, transitions) {
4965
4961
 
4966
4962
  exports.AbortedDeferredError = AbortedDeferredError;
4967
4963
  exports.Action = Action;
4968
- exports.DecodedResponse = DecodedResponse;
4969
4964
  exports.IDLE_BLOCKER = IDLE_BLOCKER;
4970
4965
  exports.IDLE_FETCHER = IDLE_FETCHER;
4971
4966
  exports.IDLE_NAVIGATION = IDLE_NAVIGATION;