@remix-run/router 1.23.2 → 1.23.4

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,21 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## v1.23.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix double slash normalization for `useNavigate` colon urls ([3ed85d5](https://github.com/remix-run/react-router/commit/3ed85d5))
8
+
9
+ - As a reminder, `navigate()` is only intended for navigations within the React Router application and not for external navigations to other domains
10
+ - This change may be a breaking bug fix if you are using `navigate` for external navigations
11
+
12
+ ## v1.23.3
13
+
14
+ ### Patch Changes
15
+
16
+ - Lift `decodePath` call out of hot path during route matching ([#15119](https://github.com/remix-run/react-router/pull/15119))
17
+ - Normalize double slashes in redirect paths ([#15118](https://github.com/remix-run/react-router/pull/15118))
18
+
3
19
  ## 1.23.2
4
20
 
5
21
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.23.2
2
+ * @remix-run/router v1.23.4
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -13,18 +13,13 @@
13
13
  Object.defineProperty(exports, '__esModule', { value: true });
14
14
 
15
15
  function _extends() {
16
- _extends = Object.assign ? Object.assign.bind() : function (target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = arguments[i];
19
- for (var key in source) {
20
- if (Object.prototype.hasOwnProperty.call(source, key)) {
21
- target[key] = source[key];
22
- }
23
- }
16
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
17
+ for (var e = 1; e < arguments.length; e++) {
18
+ var t = arguments[e];
19
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
24
20
  }
25
- return target;
26
- };
27
- return _extends.apply(this, arguments);
21
+ return n;
22
+ }, _extends.apply(null, arguments);
28
23
  }
29
24
 
30
25
  ////////////////////////////////////////////////////////////////////////////////
@@ -35,8 +30,24 @@ function _extends() {
35
30
  * Actions represent the type of change to a location value.
36
31
  */
37
32
  let Action = /*#__PURE__*/function (Action) {
33
+ /**
34
+ * A POP indicates a change to an arbitrary index in the history stack, such
35
+ * as a back or forward navigation. It does not describe the direction of the
36
+ * navigation, only that the current index changed.
37
+ *
38
+ * Note: This is the default action for newly created history objects.
39
+ */
38
40
  Action["Pop"] = "POP";
41
+ /**
42
+ * A PUSH indicates a new entry being added to the history stack, such as when
43
+ * a link is clicked and a new page loads. When this happens, all subsequent
44
+ * entries in the stack are lost.
45
+ */
39
46
  Action["Push"] = "PUSH";
47
+ /**
48
+ * A REPLACE indicates the entry at the current index in the history stack
49
+ * being replaced by a new one.
50
+ */
40
51
  Action["Replace"] = "REPLACE";
41
52
  return Action;
42
53
  }({});
@@ -47,21 +58,26 @@ let Action = /*#__PURE__*/function (Action) {
47
58
 
48
59
  // TODO: (v7) Change the Location generic default from `any` to `unknown` and
49
60
  // remove Remix `useLocation` wrapper.
61
+
50
62
  /**
51
63
  * An entry in a history stack. A location contains information about the
52
64
  * URL path, as well as possibly some arbitrary state and a key.
53
65
  */
66
+
54
67
  /**
55
68
  * A change to the current location.
56
69
  */
70
+
57
71
  /**
58
72
  * A function that receives notifications about location changes.
59
73
  */
74
+
60
75
  /**
61
76
  * Describes a location that is the destination of some navigation, either via
62
77
  * `history.push` or `history.replace`. This may be either a URL or the pieces
63
78
  * of a URL path.
64
79
  */
80
+
65
81
  /**
66
82
  * A history is an interface to the navigation stack. The history serves as the
67
83
  * source of truth for the current location, as well as provides a set of
@@ -70,6 +86,7 @@ let Action = /*#__PURE__*/function (Action) {
70
86
  * It is similar to the DOM's `window.history` object, but with a smaller, more
71
87
  * focused API.
72
88
  */
89
+
73
90
  const PopStateEventType = "popstate";
74
91
  //#endregion
75
92
 
@@ -81,11 +98,13 @@ const PopStateEventType = "popstate";
81
98
  * A user-supplied object that describes a location. Used when providing
82
99
  * entries to `createMemoryHistory` via its `initialEntries` option.
83
100
  */
101
+
84
102
  /**
85
103
  * A memory history stores locations in memory. This is useful in stateful
86
104
  * environments where there is no web browser, such as node tests or React
87
105
  * Native.
88
106
  */
107
+
89
108
  /**
90
109
  * Memory history stores the current location in memory. It is designed for use
91
110
  * in stateful non-browser environments like tests and React Native.
@@ -203,6 +222,7 @@ function createMemoryHistory(options) {
203
222
  *
204
223
  * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
205
224
  */
225
+
206
226
  /**
207
227
  * Browser history stores the location in regular URLs. This is the standard for
208
228
  * most web apps, but it requires some configuration on the server to ensure you
@@ -250,6 +270,7 @@ function createBrowserHistory(options) {
250
270
  *
251
271
  * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory
252
272
  */
273
+
253
274
  /**
254
275
  * Hash history stores the location in window.location.hash. This makes it ideal
255
276
  * for situations where you don't want to send the location to the server for
@@ -310,6 +331,7 @@ function createHashHistory(options) {
310
331
  /**
311
332
  * @private
312
333
  */
334
+
313
335
  function invariant(value, message) {
314
336
  if (value === false || value === null || typeof value === "undefined") {
315
337
  throw new Error(message);
@@ -609,26 +631,33 @@ let ResultType = /*#__PURE__*/function (ResultType) {
609
631
  // TODO: (v7) Change the defaults from any to unknown in and remove Remix wrappers:
610
632
  // ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs
611
633
  // Also, make them a type alias instead of an interface
634
+
612
635
  /**
613
636
  * Arguments passed to loader functions
614
637
  */
638
+
615
639
  /**
616
640
  * Arguments passed to action functions
617
641
  */
642
+
618
643
  /**
619
644
  * Loaders and actions can return anything except `undefined` (`null` is a
620
645
  * valid return value if there is no data to return). Responses are preferred
621
646
  * and will ease any future migration to Remix
622
647
  */
648
+
623
649
  /**
624
650
  * Route loader function signature
625
651
  */
652
+
626
653
  /**
627
654
  * Route action function signature
628
655
  */
656
+
629
657
  /**
630
658
  * Arguments passed to shouldRevalidate function
631
659
  */
660
+
632
661
  /**
633
662
  * Route shouldRevalidate function signature. This runs after any submission
634
663
  * (navigation or fetcher), so we flatten the navigation/fetcher submission
@@ -636,24 +665,29 @@ let ResultType = /*#__PURE__*/function (ResultType) {
636
665
  * or a fetcher, what really matters is the URLs and the formData since loaders
637
666
  * have to re-run based on the data models that were potentially mutated.
638
667
  */
668
+
639
669
  /**
640
670
  * Function provided by the framework-aware layers to set `hasErrorBoundary`
641
671
  * from the framework-aware `errorElement` prop
642
672
  *
643
673
  * @deprecated Use `mapRouteProperties` instead
644
674
  */
675
+
645
676
  /**
646
677
  * Result from a loader or action called via dataStrategy
647
678
  */
679
+
648
680
  /**
649
681
  * Function provided by the framework-aware layers to set any framework-specific
650
682
  * properties from framework-agnostic properties
651
683
  */
684
+
652
685
  /**
653
686
  * Keys we cannot change from within a lazy() function. We spread all other keys
654
687
  * onto the route. Either they're meaningful to the router, or they'll get
655
688
  * ignored.
656
689
  */
690
+
657
691
  const immutableRouteKeys = new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
658
692
 
659
693
  /**
@@ -697,12 +731,15 @@ const immutableRouteKeys = new Set(["lazy", "caseSensitive", "path", "id", "inde
697
731
  // Attempt to parse the given string segment. If it fails, then just return the
698
732
  // plain string type as a default fallback. Otherwise, return the union of the
699
733
  // parsed string literals that were referenced as dynamic segments in the route.
734
+
700
735
  /**
701
736
  * The parameters that were parsed from the URL path.
702
737
  */
738
+
703
739
  /**
704
740
  * A RouteMatch contains info about how a route matched a URL.
705
741
  */
742
+
706
743
  function isIndexRoute(route) {
707
744
  return route.index === true;
708
745
  }
@@ -761,6 +798,7 @@ function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
761
798
  let branches = flattenRoutes(routes);
762
799
  rankRouteBranches(branches);
763
800
  let matches = null;
801
+ let decoded = decodePath(pathname);
764
802
  for (let i = 0; matches == null && i < branches.length; ++i) {
765
803
  // Incoming pathnames are generally encoded from either window.location
766
804
  // or from router.navigate, but we want to match against the unencoded
@@ -768,7 +806,6 @@ function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
768
806
  // encoded here but there also shouldn't be anything to decode so this
769
807
  // should be a safe operation. This avoids needing matchRoutes to be
770
808
  // history-aware.
771
- let decoded = decodePath(pathname);
772
809
  matches = matchRouteBranch(branches[i], decoded, allowPartial);
773
810
  }
774
811
  return matches;
@@ -1140,8 +1177,6 @@ function stripBasename(pathname, basename) {
1140
1177
  }
1141
1178
  return pathname.slice(startIndex) || "/";
1142
1179
  }
1143
- const ABSOLUTE_URL_REGEX$1 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1144
- const isAbsoluteUrl = url => ABSOLUTE_URL_REGEX$1.test(url);
1145
1180
 
1146
1181
  /**
1147
1182
  * Returns a resolved path object relative to the given pathname.
@@ -1159,19 +1194,11 @@ function resolvePath(to, fromPathname) {
1159
1194
  } = typeof to === "string" ? parsePath(to) : to;
1160
1195
  let pathname;
1161
1196
  if (toPathname) {
1162
- if (isAbsoluteUrl(toPathname)) {
1163
- pathname = toPathname;
1197
+ toPathname = removeDoubleSlashes(toPathname);
1198
+ if (toPathname.startsWith("/")) {
1199
+ pathname = resolvePathname(toPathname.substring(1), "/");
1164
1200
  } else {
1165
- if (toPathname.includes("//")) {
1166
- let oldPathname = toPathname;
1167
- toPathname = toPathname.replace(/\/\/+/g, "/");
1168
- warning(false, "Pathnames cannot have embedded double slashes - normalizing " + (oldPathname + " -> " + toPathname));
1169
- }
1170
- if (toPathname.startsWith("/")) {
1171
- pathname = resolvePathname(toPathname.substring(1), "/");
1172
- } else {
1173
- pathname = resolvePathname(toPathname, fromPathname);
1174
- }
1201
+ pathname = resolvePathname(toPathname, fromPathname);
1175
1202
  }
1176
1203
  } else {
1177
1204
  pathname = fromPathname;
@@ -1307,11 +1334,12 @@ function getToPathname(to) {
1307
1334
  // Empty strings should be treated the same as / paths
1308
1335
  return to === "" || to.pathname === "" ? "/" : typeof to === "string" ? parsePath(to).pathname : to.pathname;
1309
1336
  }
1337
+ const removeDoubleSlashes = path => path.replace(/\/\/+/g, "/");
1310
1338
 
1311
1339
  /**
1312
1340
  * @private
1313
1341
  */
1314
- const joinPaths = paths => paths.join("/").replace(/\/\/+/g, "/");
1342
+ const joinPaths = paths => removeDoubleSlashes(paths.join("/"));
1315
1343
 
1316
1344
  /**
1317
1345
  * @private
@@ -1604,69 +1632,92 @@ function isRouteErrorResponse(error) {
1604
1632
  /**
1605
1633
  * A Router instance manages all navigation and data loading/mutations
1606
1634
  */
1635
+
1607
1636
  /**
1608
1637
  * State maintained internally by the router. During a navigation, all states
1609
1638
  * reflect the the "old" location unless otherwise noted.
1610
1639
  */
1640
+
1611
1641
  /**
1612
1642
  * Data that can be passed into hydrate a Router from SSR
1613
1643
  */
1644
+
1614
1645
  /**
1615
1646
  * Future flags to toggle new feature behavior
1616
1647
  */
1648
+
1617
1649
  /**
1618
1650
  * Initialization options for createRouter
1619
1651
  */
1652
+
1620
1653
  /**
1621
1654
  * State returned from a server-side query() call
1622
1655
  */
1656
+
1623
1657
  /**
1624
1658
  * A StaticHandler instance manages a singular SSR navigation/fetch event
1625
1659
  */
1660
+
1626
1661
  /**
1627
1662
  * Subscriber function signature for changes to router state
1628
1663
  */
1664
+
1629
1665
  /**
1630
1666
  * Function signature for determining the key to be used in scroll restoration
1631
1667
  * for a given location
1632
1668
  */
1669
+
1633
1670
  /**
1634
1671
  * Function signature for determining the current scroll position
1635
1672
  */
1673
+
1636
1674
  // Allowed for any navigation or fetch
1675
+
1637
1676
  // Only allowed for navigations
1677
+
1638
1678
  // Only allowed for submission navigations
1679
+
1639
1680
  /**
1640
1681
  * Options for a navigate() call for a normal (non-submission) navigation
1641
1682
  */
1683
+
1642
1684
  /**
1643
1685
  * Options for a navigate() call for a submission navigation
1644
1686
  */
1687
+
1645
1688
  /**
1646
1689
  * Options to pass to navigate() for a navigation
1647
1690
  */
1691
+
1648
1692
  /**
1649
1693
  * Options for a fetch() load
1650
1694
  */
1695
+
1651
1696
  /**
1652
1697
  * Options for a fetch() submission
1653
1698
  */
1699
+
1654
1700
  /**
1655
1701
  * Options to pass to fetch()
1656
1702
  */
1703
+
1657
1704
  /**
1658
1705
  * Potential states for state.navigation
1659
1706
  */
1707
+
1660
1708
  /**
1661
1709
  * Potential states for fetchers
1662
1710
  */
1711
+
1663
1712
  /**
1664
1713
  * Cached info for active fetcher.load() instances so they can participate
1665
1714
  * in revalidation
1666
1715
  */
1716
+
1667
1717
  /**
1668
1718
  * Identified fetcher.load() calls that need to be revalidated
1669
1719
  */
1720
+
1670
1721
  const validMutationMethodsArr = ["post", "put", "patch", "delete"];
1671
1722
  const validMutationMethods = new Set(validMutationMethodsArr);
1672
1723
  const validRequestMethodsArr = ["get", ...validMutationMethodsArr];
@@ -4969,7 +5020,7 @@ function normalizeRedirectLocation(location, currentUrl, basename, historyInstan
4969
5020
  }
4970
5021
  let isSameBasename = stripBasename(url.pathname, basename) != null;
4971
5022
  if (url.origin === currentUrl.origin && isSameBasename) {
4972
- return url.pathname + url.search + url.hash;
5023
+ return removeDoubleSlashes(url.pathname) + url.search + url.hash;
4973
5024
  }
4974
5025
  }
4975
5026
  try {