react-router 5.2.0 → 5.2.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/modules/Router.js CHANGED
@@ -48,7 +48,11 @@ class Router extends React.Component {
48
48
  }
49
49
 
50
50
  componentWillUnmount() {
51
- if (this.unlisten) this.unlisten();
51
+ if (this.unlisten) {
52
+ this.unlisten();
53
+ this._isMounted = false;
54
+ this._pendingLocation = null;
55
+ }
52
56
  }
53
57
 
54
58
  render() {
@@ -1,12 +1,4 @@
1
- // TODO: Replace with React.createContext once we can assume React 16+
2
- import createContext from "mini-create-react-context";
3
-
4
- const createNamedContext = name => {
5
- const context = createContext();
6
- context.displayName = name;
7
-
8
- return context;
9
- };
1
+ import createNamedContext from "./createNameContext";
10
2
 
11
3
  const context = /*#__PURE__*/ createNamedContext("Router");
12
4
  export default context;
package/modules/hooks.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import invariant from "tiny-invariant";
3
3
 
4
- import Context from "./RouterContext.js";
4
+ import RouterContext from "./RouterContext.js";
5
5
  import HistoryContext from "./HistoryContext.js";
6
6
  import matchPath from "./matchPath.js";
7
7
 
@@ -26,7 +26,7 @@ export function useLocation() {
26
26
  );
27
27
  }
28
28
 
29
- return useContext(Context).location;
29
+ return useContext(RouterContext).location;
30
30
  }
31
31
 
32
32
  export function useParams() {
@@ -37,7 +37,7 @@ export function useParams() {
37
37
  );
38
38
  }
39
39
 
40
- const match = useContext(Context).match;
40
+ const match = useContext(RouterContext).match;
41
41
  return match ? match.params : {};
42
42
  }
43
43
 
@@ -50,7 +50,6 @@ export function useRouteMatch(path) {
50
50
  }
51
51
 
52
52
  const location = useLocation();
53
- const match = useContext(Context).match;
54
-
53
+ const match = useContext(RouterContext).match;
55
54
  return path ? matchPath(location.pathname, path) : match;
56
55
  }
package/modules/index.js CHANGED
@@ -32,8 +32,7 @@ export { default as generatePath } from "./generatePath.js";
32
32
  export { default as matchPath } from "./matchPath.js";
33
33
  export { default as withRouter } from "./withRouter.js";
34
34
 
35
- import { useHistory, useLocation, useParams, useRouteMatch } from "./hooks.js";
36
- export { useHistory, useLocation, useParams, useRouteMatch };
37
-
38
35
  export { default as __HistoryContext } from "./HistoryContext.js";
39
36
  export { default as __RouterContext } from "./RouterContext.js";
37
+
38
+ export { useHistory, useLocation, useParams, useRouteMatch } from "./hooks.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-router",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "Declarative routing for React",
5
5
  "repository": "ReactTraining/react-router",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "react": ">=15"
37
37
  },
38
38
  "dependencies": {
39
- "@babel/runtime": "^7.1.2",
39
+ "@babel/runtime": "^7.12.13",
40
40
  "history": "^4.9.0",
41
41
  "hoist-non-react-statics": "^3.1.0",
42
42
  "loose-envify": "^1.3.1",
@@ -59,6 +59,5 @@
59
59
  "routing",
60
60
  "history",
61
61
  "link"
62
- ],
63
- "gitHead": "21a62e55c0d6196002bd4ab5b3350514976928cf"
62
+ ]
64
63
  }
@@ -6,10 +6,19 @@
6
6
 
7
7
  var React__default = 'default' in React ? React['default'] : React;
8
8
 
9
+ function _setPrototypeOf(o, p) {
10
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
11
+ o.__proto__ = p;
12
+ return o;
13
+ };
14
+
15
+ return _setPrototypeOf(o, p);
16
+ }
17
+
9
18
  function _inheritsLoose(subClass, superClass) {
10
19
  subClass.prototype = Object.create(superClass.prototype);
11
20
  subClass.prototype.constructor = subClass;
12
- subClass.__proto__ = superClass;
21
+ _setPrototypeOf(subClass, superClass);
13
22
  }
14
23
 
15
24
  function unwrapExports (x) {
@@ -1571,12 +1580,6 @@
1571
1580
  return history;
1572
1581
  }
1573
1582
 
1574
- function _inheritsLoose$1(subClass, superClass) {
1575
- subClass.prototype = Object.create(superClass.prototype);
1576
- subClass.prototype.constructor = subClass;
1577
- subClass.__proto__ = superClass;
1578
- }
1579
-
1580
1583
  var MAX_SIGNED_31_BIT_INT = 1073741823;
1581
1584
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
1582
1585
 
@@ -1626,7 +1629,7 @@
1626
1629
  var contextProp = '__create-react-context-' + getUniqueId() + '__';
1627
1630
 
1628
1631
  var Provider = /*#__PURE__*/function (_Component) {
1629
- _inheritsLoose$1(Provider, _Component);
1632
+ _inheritsLoose(Provider, _Component);
1630
1633
 
1631
1634
  function Provider() {
1632
1635
  var _this;
@@ -1678,7 +1681,7 @@
1678
1681
  Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = propTypes.object.isRequired, _Provider$childContex);
1679
1682
 
1680
1683
  var Consumer = /*#__PURE__*/function (_Component2) {
1681
- _inheritsLoose$1(Consumer, _Component2);
1684
+ _inheritsLoose(Consumer, _Component2);
1682
1685
 
1683
1686
  function Consumer() {
1684
1687
  var _this2;
@@ -1755,29 +1758,15 @@
1755
1758
  return context;
1756
1759
  };
1757
1760
 
1758
- var historyContext =
1759
- /*#__PURE__*/
1760
- createNamedContext("Router-History");
1761
+ var historyContext = /*#__PURE__*/createNamedContext("Router-History");
1761
1762
 
1762
- // TODO: Replace with React.createContext once we can assume React 16+
1763
-
1764
- var createNamedContext$1 = function createNamedContext(name) {
1765
- var context = index();
1766
- context.displayName = name;
1767
- return context;
1768
- };
1769
-
1770
- var context =
1771
- /*#__PURE__*/
1772
- createNamedContext$1("Router");
1763
+ var context = /*#__PURE__*/createNamedContext("Router");
1773
1764
 
1774
1765
  /**
1775
1766
  * The public API for putting history on context.
1776
1767
  */
1777
1768
 
1778
- var Router =
1779
- /*#__PURE__*/
1780
- function (_React$Component) {
1769
+ var Router = /*#__PURE__*/function (_React$Component) {
1781
1770
  _inheritsLoose(Router, _React$Component);
1782
1771
 
1783
1772
  Router.computeRootMatch = function computeRootMatch(pathname) {
@@ -1832,18 +1821,22 @@
1832
1821
  };
1833
1822
 
1834
1823
  _proto.componentWillUnmount = function componentWillUnmount() {
1835
- if (this.unlisten) this.unlisten();
1824
+ if (this.unlisten) {
1825
+ this.unlisten();
1826
+ this._isMounted = false;
1827
+ this._pendingLocation = null;
1828
+ }
1836
1829
  };
1837
1830
 
1838
1831
  _proto.render = function render() {
1839
- return React__default.createElement(context.Provider, {
1832
+ return /*#__PURE__*/React__default.createElement(context.Provider, {
1840
1833
  value: {
1841
1834
  history: this.props.history,
1842
1835
  location: this.state.location,
1843
1836
  match: Router.computeRootMatch(this.state.location.pathname),
1844
1837
  staticContext: this.props.staticContext
1845
1838
  }
1846
- }, React__default.createElement(historyContext.Provider, {
1839
+ }, /*#__PURE__*/React__default.createElement(historyContext.Provider, {
1847
1840
  children: this.props.children || null,
1848
1841
  value: this.props.history
1849
1842
  }));
@@ -1868,9 +1861,7 @@
1868
1861
  * The public API for a <Router> that stores location in memory.
1869
1862
  */
1870
1863
 
1871
- var MemoryRouter =
1872
- /*#__PURE__*/
1873
- function (_React$Component) {
1864
+ var MemoryRouter = /*#__PURE__*/function (_React$Component) {
1874
1865
  _inheritsLoose(MemoryRouter, _React$Component);
1875
1866
 
1876
1867
  function MemoryRouter() {
@@ -1888,7 +1879,7 @@
1888
1879
  var _proto = MemoryRouter.prototype;
1889
1880
 
1890
1881
  _proto.render = function render() {
1891
- return React__default.createElement(Router, {
1882
+ return /*#__PURE__*/React__default.createElement(Router, {
1892
1883
  history: this.history,
1893
1884
  children: this.props.children
1894
1885
  });
@@ -1911,9 +1902,7 @@
1911
1902
  };
1912
1903
  }
1913
1904
 
1914
- var Lifecycle =
1915
- /*#__PURE__*/
1916
- function (_React$Component) {
1905
+ var Lifecycle = /*#__PURE__*/function (_React$Component) {
1917
1906
  _inheritsLoose(Lifecycle, _React$Component);
1918
1907
 
1919
1908
  function Lifecycle() {
@@ -1949,11 +1938,11 @@
1949
1938
  var message = _ref.message,
1950
1939
  _ref$when = _ref.when,
1951
1940
  when = _ref$when === void 0 ? true : _ref$when;
1952
- return React__default.createElement(context.Consumer, null, function (context) {
1941
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context) {
1953
1942
  !context ? invariant(false, "You should not use <Prompt> outside a <Router>") : void 0;
1954
1943
  if (!when || context.staticContext) return null;
1955
1944
  var method = context.history.block;
1956
- return React__default.createElement(Lifecycle, {
1945
+ return /*#__PURE__*/React__default.createElement(Lifecycle, {
1957
1946
  onMount: function onMount(self) {
1958
1947
  self.release = method(message);
1959
1948
  },
@@ -2455,7 +2444,7 @@
2455
2444
  to = _ref.to,
2456
2445
  _ref$push = _ref.push,
2457
2446
  push = _ref$push === void 0 ? false : _ref$push;
2458
- return React__default.createElement(context.Consumer, null, function (context) {
2447
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context) {
2459
2448
  !context ? invariant(false, "You should not use <Redirect> outside a <Router>") : void 0;
2460
2449
  var history = context.history,
2461
2450
  staticContext = context.staticContext;
@@ -2470,7 +2459,7 @@
2470
2459
  return null;
2471
2460
  }
2472
2461
 
2473
- return React__default.createElement(Lifecycle, {
2462
+ return /*#__PURE__*/React__default.createElement(Lifecycle, {
2474
2463
  onMount: function onMount() {
2475
2464
  method(location);
2476
2465
  },
@@ -2590,9 +2579,7 @@
2590
2579
  */
2591
2580
 
2592
2581
 
2593
- var Route =
2594
- /*#__PURE__*/
2595
- function (_React$Component) {
2582
+ var Route = /*#__PURE__*/function (_React$Component) {
2596
2583
  _inheritsLoose(Route, _React$Component);
2597
2584
 
2598
2585
  function Route() {
@@ -2604,7 +2591,7 @@
2604
2591
  _proto.render = function render() {
2605
2592
  var _this = this;
2606
2593
 
2607
- return React__default.createElement(context.Consumer, null, function (context$1) {
2594
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context$1) {
2608
2595
  !context$1 ? invariant(false, "You should not use <Route> outside a <Router>") : void 0;
2609
2596
  var location = _this.props.location || context$1.location;
2610
2597
  var match = _this.props.computedMatch ? _this.props.computedMatch // <Switch> already computed the match for us
@@ -2621,13 +2608,13 @@
2621
2608
  render = _this$props.render; // Preact uses an empty array as children by
2622
2609
  // default, so use null if that's the case.
2623
2610
 
2624
- if (Array.isArray(children) && children.length === 0) {
2611
+ if (Array.isArray(children) && isEmptyChildren(children)) {
2625
2612
  children = null;
2626
2613
  }
2627
2614
 
2628
- return React__default.createElement(context.Provider, {
2615
+ return /*#__PURE__*/React__default.createElement(context.Provider, {
2629
2616
  value: props
2630
- }, props.match ? children ? typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : children : component ? React__default.createElement(component, props) : render ? render(props) : null : typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : null);
2617
+ }, props.match ? children ? typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : children : component ? /*#__PURE__*/React__default.createElement(component, props) : render ? render(props) : null : typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : null);
2631
2618
  });
2632
2619
  };
2633
2620
 
@@ -2716,9 +2703,7 @@
2716
2703
  */
2717
2704
 
2718
2705
 
2719
- var StaticRouter =
2720
- /*#__PURE__*/
2721
- function (_React$Component) {
2706
+ var StaticRouter = /*#__PURE__*/function (_React$Component) {
2722
2707
  _inheritsLoose(StaticRouter, _React$Component);
2723
2708
 
2724
2709
  function StaticRouter() {
@@ -2786,7 +2771,7 @@
2786
2771
  listen: this.handleListen,
2787
2772
  block: this.handleBlock
2788
2773
  };
2789
- return React__default.createElement(Router, _extends({}, rest, {
2774
+ return /*#__PURE__*/React__default.createElement(Router, _extends({}, rest, {
2790
2775
  history: history,
2791
2776
  staticContext: context
2792
2777
  }));
@@ -2811,9 +2796,7 @@
2811
2796
  * The public API for rendering the first <Route> that matches.
2812
2797
  */
2813
2798
 
2814
- var Switch =
2815
- /*#__PURE__*/
2816
- function (_React$Component) {
2799
+ var Switch = /*#__PURE__*/function (_React$Component) {
2817
2800
  _inheritsLoose(Switch, _React$Component);
2818
2801
 
2819
2802
  function Switch() {
@@ -2825,7 +2808,7 @@
2825
2808
  _proto.render = function render() {
2826
2809
  var _this = this;
2827
2810
 
2828
- return React__default.createElement(context.Consumer, null, function (context) {
2811
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context) {
2829
2812
  !context ? invariant(false, "You should not use <Switch> outside a <Router>") : void 0;
2830
2813
  var location = _this.props.location || context.location;
2831
2814
  var element, match; // We use React.Children.forEach instead of React.Children.toArray().find()
@@ -2834,7 +2817,7 @@
2834
2817
  // component at different URLs.
2835
2818
 
2836
2819
  React__default.Children.forEach(_this.props.children, function (child) {
2837
- if (match == null && React__default.isValidElement(child)) {
2820
+ if (match == null && /*#__PURE__*/React__default.isValidElement(child)) {
2838
2821
  element = child;
2839
2822
  var path = child.props.path || child.props.from;
2840
2823
  match = path ? matchPath(location.pathname, _extends({}, child.props, {
@@ -2842,7 +2825,7 @@
2842
2825
  })) : context.match;
2843
2826
  }
2844
2827
  });
2845
- return match ? React__default.cloneElement(element, {
2828
+ return match ? /*#__PURE__*/React__default.cloneElement(element, {
2846
2829
  location: location,
2847
2830
  computedMatch: match
2848
2831
  }) : null;
@@ -2977,9 +2960,9 @@
2977
2960
  var wrappedComponentRef = props.wrappedComponentRef,
2978
2961
  remainingProps = _objectWithoutPropertiesLoose(props, ["wrappedComponentRef"]);
2979
2962
 
2980
- return React__default.createElement(context.Consumer, null, function (context) {
2963
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context) {
2981
2964
  !context ? invariant(false, "You should not use <" + displayName + " /> outside a <Router>") : void 0;
2982
- return React__default.createElement(Component, _extends({}, remainingProps, context, {
2965
+ return /*#__PURE__*/React__default.createElement(Component, _extends({}, remainingProps, context, {
2983
2966
  ref: wrappedComponentRef
2984
2967
  }));
2985
2968
  });