@remix-run/router 1.9.0-pre.0 → 1.9.0-pre.1

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,15 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.9.0-pre.1
4
+
5
+ ### Patch Changes
6
+
7
+ - In order to move towards stricter TypeScript support in the future, we're aiming to replace current usages of `any` with `unknown` on exposed typings for user-provided data. To do this in Remix v2 without introducing breaking changes in React Router v6, we have added generics to a number of shared types. These continue to default to `any` in React Router and are overridden with `unknown` in Remix. In React Router v7 we plan to move these to `unknown` as a breakjing change. ([#10843](https://github.com/remix-run/react-router/pull/10843))
8
+
9
+ - `Location` now accepts a generic for the `location.state` value
10
+ - `ActionFunctionArgs`/`ActionFunction`/`LoaderFunctionArgs`/`LoaderFunction` now accept a generic for the `context` parameter (only used in SSR usages via `createStaticHandler`)
11
+ - The return type of `useMatches` (now exported as `UIMatch`) accepts generics for `match.data` and `match.handle` - both of which were already set to `unknown`
12
+
3
13
  ## 1.9.0-pre.0
4
14
 
5
15
  ### Minor Changes
package/dist/history.d.ts CHANGED
@@ -43,11 +43,11 @@ export interface Path {
43
43
  * An entry in a history stack. A location contains information about the
44
44
  * URL path, as well as possibly some arbitrary state and a key.
45
45
  */
46
- export interface Location extends Path {
46
+ export interface Location<S = any> extends Path {
47
47
  /**
48
48
  * A value of arbitrary data associated with this location.
49
49
  */
50
- state: any;
50
+ state: S;
51
51
  /**
52
52
  * A unique string associated with this location. May be used to safely store
53
53
  * and retrieve data in some other storage API, like `localStorage`.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, V7_FormMethod, } from "./utils";
1
+ export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, 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";
5
5
  export * from "./router";
6
6
  /** @internal */
7
7
  export type { RouteManifest as UNSAFE_RouteManifest } from "./utils";
8
- export { DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, } from "./utils";
8
+ export { DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, convertRouteMatchToUiMatch as UNSAFE_convertRouteMatchToUiMatch, getPathContributingMatches as UNSAFE_getPathContributingMatches, } from "./utils";
9
9
  export { invariant as UNSAFE_invariant, warning as UNSAFE_warning, } from "./history";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.9.0-pre.0
2
+ * @remix-run/router v1.9.0-pre.1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -45,25 +45,23 @@ let Action = /*#__PURE__*/function (Action) {
45
45
  * The pathname, search, and hash values of a URL.
46
46
  */
47
47
 
48
+ // TODO: (v7) Change the Location generic default from `any` to `unknown` and
49
+ // remove Remix `useLocation` wrapper.
48
50
  /**
49
51
  * An entry in a history stack. A location contains information about the
50
52
  * URL path, as well as possibly some arbitrary state and a key.
51
53
  */
52
-
53
54
  /**
54
55
  * A change to the current location.
55
56
  */
56
-
57
57
  /**
58
58
  * A function that receives notifications about location changes.
59
59
  */
60
-
61
60
  /**
62
61
  * Describes a location that is the destination of some navigation, either via
63
62
  * `history.push` or `history.replace`. May be either a URL or the pieces of a
64
63
  * URL path.
65
64
  */
66
-
67
65
  /**
68
66
  * A history is an interface to the navigation stack. The history serves as the
69
67
  * source of truth for the current location, as well as provides a set of
@@ -72,7 +70,6 @@ let Action = /*#__PURE__*/function (Action) {
72
70
  * It is similar to the DOM's `window.history` object, but with a smaller, more
73
71
  * focused API.
74
72
  */
75
-
76
73
  const PopStateEventType = "popstate";
77
74
  //#endregion
78
75
 
@@ -605,32 +602,28 @@ let ResultType = /*#__PURE__*/function (ResultType) {
605
602
  * this as a private implementation detail in case they diverge in the future.
606
603
  */
607
604
 
605
+ // TODO: (v7) Change the defaults from any to unknown in and remove Remix wrappers:
606
+ // ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs
608
607
  /**
609
608
  * Arguments passed to loader functions
610
609
  */
611
-
612
610
  /**
613
611
  * Arguments passed to action functions
614
612
  */
615
-
616
613
  /**
617
614
  * Loaders and actions can return anything except `undefined` (`null` is a
618
615
  * valid return value if there is no data to return). Responses are preferred
619
616
  * and will ease any future migration to Remix
620
617
  */
621
-
622
618
  /**
623
619
  * Route loader function signature
624
620
  */
625
-
626
621
  /**
627
622
  * Route action function signature
628
623
  */
629
-
630
624
  /**
631
625
  * Arguments passed to shouldRevalidate function
632
626
  */
633
-
634
627
  /**
635
628
  * Route shouldRevalidate function signature. This runs after any submission
636
629
  * (navigation or fetcher), so we flatten the navigation/fetcher submission
@@ -638,25 +631,21 @@ let ResultType = /*#__PURE__*/function (ResultType) {
638
631
  * or a fetcher, what really matters is the URLs and the formData since loaders
639
632
  * have to re-run based on the data models that were potentially mutated.
640
633
  */
641
-
642
634
  /**
643
635
  * Function provided by the framework-aware layers to set `hasErrorBoundary`
644
636
  * from the framework-aware `errorElement` prop
645
637
  *
646
638
  * @deprecated Use `mapRouteProperties` instead
647
639
  */
648
-
649
640
  /**
650
641
  * Function provided by the framework-aware layers to set any framework-specific
651
642
  * properties from framework-agnostic properties
652
643
  */
653
-
654
644
  /**
655
645
  * Keys we cannot change from within a lazy() function. We spread all other keys
656
646
  * onto the route. Either they're meaningful to the router, or they'll get
657
647
  * ignored.
658
648
  */
659
-
660
649
  const immutableRouteKeys = new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
661
650
 
662
651
  /**
@@ -773,6 +762,20 @@ function matchRoutes(routes, locationArg, basename) {
773
762
  }
774
763
  return matches;
775
764
  }
765
+ function convertRouteMatchToUiMatch(match, loaderData) {
766
+ let {
767
+ route,
768
+ pathname,
769
+ params
770
+ } = match;
771
+ return {
772
+ id: route.id,
773
+ pathname,
774
+ params,
775
+ data: loaderData[route.id],
776
+ handle: route.handle
777
+ };
778
+ }
776
779
  function flattenRoutes(routes, branches, parentsMeta, parentPath) {
777
780
  if (branches === void 0) {
778
781
  branches = [];
@@ -2972,7 +2975,7 @@ function createRouter(init) {
2972
2975
  }
2973
2976
  function getScrollKey(location, matches) {
2974
2977
  if (getScrollRestorationKey) {
2975
- let key = getScrollRestorationKey(location, matches.map(m => createUseMatchesMatch(m, state.loaderData)));
2978
+ let key = getScrollRestorationKey(location, matches.map(m => convertRouteMatchToUiMatch(m, state.loaderData)));
2976
2979
  return key || location.key;
2977
2980
  }
2978
2981
  return location.key;
@@ -4377,23 +4380,6 @@ async function resolveDeferredData(result, signal, unwrap) {
4377
4380
  function hasNakedIndexQuery(search) {
4378
4381
  return new URLSearchParams(search).getAll("index").some(v => v === "");
4379
4382
  }
4380
-
4381
- // Note: This should match the format exported by useMatches, so if you change
4382
- // this please also change that :) Eventually we'll DRY this up
4383
- function createUseMatchesMatch(match, loaderData) {
4384
- let {
4385
- route,
4386
- pathname,
4387
- params
4388
- } = match;
4389
- return {
4390
- id: route.id,
4391
- pathname,
4392
- params,
4393
- data: loaderData[route.id],
4394
- handle: route.handle
4395
- };
4396
- }
4397
4383
  function getTargetMatch(matches, location) {
4398
4384
  let search = typeof location === "string" ? parsePath(location).search : location.search;
4399
4385
  if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
@@ -4549,6 +4535,7 @@ exports.IDLE_NAVIGATION = IDLE_NAVIGATION;
4549
4535
  exports.UNSAFE_DEFERRED_SYMBOL = UNSAFE_DEFERRED_SYMBOL;
4550
4536
  exports.UNSAFE_DeferredData = DeferredData;
4551
4537
  exports.UNSAFE_ErrorResponseImpl = ErrorResponseImpl;
4538
+ exports.UNSAFE_convertRouteMatchToUiMatch = convertRouteMatchToUiMatch;
4552
4539
  exports.UNSAFE_convertRoutesToDataRoutes = convertRoutesToDataRoutes;
4553
4540
  exports.UNSAFE_getPathContributingMatches = getPathContributingMatches;
4554
4541
  exports.UNSAFE_invariant = invariant;