@remix-run/router 1.23.2-pre-v6.0 → 1.23.3

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,6 +1,13 @@
1
1
  # `@remix-run/router`
2
2
 
3
- ## 1.23.2-pre-v6.0
3
+ ## v1.23.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Lift `decodePath` call out of hot path during route matching ([#15119](https://github.com/remix-run/react-router/pull/15119))
8
+ - Normalize double slashes in redirect paths ([#15118](https://github.com/remix-run/react-router/pull/15118))
9
+
10
+ ## 1.23.2
4
11
 
5
12
  ### Patch Changes
6
13
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.23.2-pre-v6.0
2
+ * @remix-run/router v1.23.3
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;
@@ -1164,7 +1201,7 @@ function resolvePath(to, fromPathname) {
1164
1201
  } else {
1165
1202
  if (toPathname.includes("//")) {
1166
1203
  let oldPathname = toPathname;
1167
- toPathname = toPathname.replace(/\/\/+/g, "/");
1204
+ toPathname = removeDoubleSlashes(toPathname);
1168
1205
  warning(false, "Pathnames cannot have embedded double slashes - normalizing " + (oldPathname + " -> " + toPathname));
1169
1206
  }
1170
1207
  if (toPathname.startsWith("/")) {
@@ -1307,11 +1344,12 @@ function getToPathname(to) {
1307
1344
  // Empty strings should be treated the same as / paths
1308
1345
  return to === "" || to.pathname === "" ? "/" : typeof to === "string" ? parsePath(to).pathname : to.pathname;
1309
1346
  }
1347
+ const removeDoubleSlashes = path => path.replace(/\/\/+/g, "/");
1310
1348
 
1311
1349
  /**
1312
1350
  * @private
1313
1351
  */
1314
- const joinPaths = paths => paths.join("/").replace(/\/\/+/g, "/");
1352
+ const joinPaths = paths => removeDoubleSlashes(paths.join("/"));
1315
1353
 
1316
1354
  /**
1317
1355
  * @private
@@ -1604,69 +1642,92 @@ function isRouteErrorResponse(error) {
1604
1642
  /**
1605
1643
  * A Router instance manages all navigation and data loading/mutations
1606
1644
  */
1645
+
1607
1646
  /**
1608
1647
  * State maintained internally by the router. During a navigation, all states
1609
1648
  * reflect the the "old" location unless otherwise noted.
1610
1649
  */
1650
+
1611
1651
  /**
1612
1652
  * Data that can be passed into hydrate a Router from SSR
1613
1653
  */
1654
+
1614
1655
  /**
1615
1656
  * Future flags to toggle new feature behavior
1616
1657
  */
1658
+
1617
1659
  /**
1618
1660
  * Initialization options for createRouter
1619
1661
  */
1662
+
1620
1663
  /**
1621
1664
  * State returned from a server-side query() call
1622
1665
  */
1666
+
1623
1667
  /**
1624
1668
  * A StaticHandler instance manages a singular SSR navigation/fetch event
1625
1669
  */
1670
+
1626
1671
  /**
1627
1672
  * Subscriber function signature for changes to router state
1628
1673
  */
1674
+
1629
1675
  /**
1630
1676
  * Function signature for determining the key to be used in scroll restoration
1631
1677
  * for a given location
1632
1678
  */
1679
+
1633
1680
  /**
1634
1681
  * Function signature for determining the current scroll position
1635
1682
  */
1683
+
1636
1684
  // Allowed for any navigation or fetch
1685
+
1637
1686
  // Only allowed for navigations
1687
+
1638
1688
  // Only allowed for submission navigations
1689
+
1639
1690
  /**
1640
1691
  * Options for a navigate() call for a normal (non-submission) navigation
1641
1692
  */
1693
+
1642
1694
  /**
1643
1695
  * Options for a navigate() call for a submission navigation
1644
1696
  */
1697
+
1645
1698
  /**
1646
1699
  * Options to pass to navigate() for a navigation
1647
1700
  */
1701
+
1648
1702
  /**
1649
1703
  * Options for a fetch() load
1650
1704
  */
1705
+
1651
1706
  /**
1652
1707
  * Options for a fetch() submission
1653
1708
  */
1709
+
1654
1710
  /**
1655
1711
  * Options to pass to fetch()
1656
1712
  */
1713
+
1657
1714
  /**
1658
1715
  * Potential states for state.navigation
1659
1716
  */
1717
+
1660
1718
  /**
1661
1719
  * Potential states for fetchers
1662
1720
  */
1721
+
1663
1722
  /**
1664
1723
  * Cached info for active fetcher.load() instances so they can participate
1665
1724
  * in revalidation
1666
1725
  */
1726
+
1667
1727
  /**
1668
1728
  * Identified fetcher.load() calls that need to be revalidated
1669
1729
  */
1730
+
1670
1731
  const validMutationMethodsArr = ["post", "put", "patch", "delete"];
1671
1732
  const validMutationMethods = new Set(validMutationMethodsArr);
1672
1733
  const validRequestMethodsArr = ["get", ...validMutationMethodsArr];
@@ -4969,7 +5030,7 @@ function normalizeRedirectLocation(location, currentUrl, basename, historyInstan
4969
5030
  }
4970
5031
  let isSameBasename = stripBasename(url.pathname, basename) != null;
4971
5032
  if (url.origin === currentUrl.origin && isSameBasename) {
4972
- return url.pathname + url.search + url.hash;
5033
+ return removeDoubleSlashes(url.pathname) + url.search + url.hash;
4973
5034
  }
4974
5035
  }
4975
5036
  try {