@react-devtools-plus/kit 0.9.5 → 0.9.6

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.
Files changed (3) hide show
  1. package/dist/index.cjs +119 -11
  2. package/dist/index.js +119 -11
  3. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -1666,6 +1666,104 @@ function getV5ComponentName(props) {
1666
1666
  if (typeof props.children === "function") return "children()";
1667
1667
  }
1668
1668
  /**
1669
+ * Check if a component is likely a React Router v5 Route by its props
1670
+ */
1671
+ function isLikelyV5Route(props) {
1672
+ if (!props) return false;
1673
+ const hasPath = typeof props.path === "string" || props.path === void 0;
1674
+ const hasRouteProps = props.component || props.render || props.children !== void 0;
1675
+ const hasExactOrStrict = props.exact !== void 0 || props.strict !== void 0;
1676
+ const hasLocation = props.location !== void 0;
1677
+ const hasComputedMatch = props.computedMatch !== void 0;
1678
+ return hasPath && hasRouteProps || hasExactOrStrict || hasComputedMatch || hasLocation;
1679
+ }
1680
+ /**
1681
+ * Check if a component is likely a React Router v5 Switch by its props/children
1682
+ */
1683
+ function isLikelyV5Switch(props) {
1684
+ if (!props || !props.children) return false;
1685
+ const children = Array.isArray(props.children) ? props.children : [props.children];
1686
+ for (const child of children) if (child && child.props) {
1687
+ if (isLikelyV5Route(child.props)) return true;
1688
+ }
1689
+ return false;
1690
+ }
1691
+ /**
1692
+ * Check if a component is likely a React Router v5 Redirect by its props
1693
+ */
1694
+ function isLikelyV5Redirect(props) {
1695
+ if (!props) return false;
1696
+ return typeof props.to === "string" || typeof props.to === "object" && props.to !== null;
1697
+ }
1698
+ /**
1699
+ * Check if a fiber node is a React Router v5 context provider
1700
+ * React Router v5 uses __RouterContext with value containing { history, location, match, staticContext }
1701
+ */
1702
+ function isRouterContextProvider(fiber) {
1703
+ const props = fiber.memoizedProps || fiber.pendingProps;
1704
+ if (!(props === null || props === void 0 ? void 0 : props.value)) return false;
1705
+ const value = props.value;
1706
+ return !!(value.history && value.location && typeof value.match === "object");
1707
+ }
1708
+ /**
1709
+ * Check if a fiber node is a React Router v5 Route context provider
1710
+ * Route wraps children in a context provider with match info
1711
+ */
1712
+ function isRouteContextProvider(fiber) {
1713
+ const props = fiber.memoizedProps || fiber.pendingProps;
1714
+ if (!(props === null || props === void 0 ? void 0 : props.value)) return false;
1715
+ const value = props.value;
1716
+ return !!(value.match && typeof value.match.path === "string");
1717
+ }
1718
+ /**
1719
+ * Extract routes from React Router v5 by traversing fiber tree and finding Route context providers
1720
+ * This works even when component names are minified
1721
+ */
1722
+ function extractRoutesFromFiberV5(fiber) {
1723
+ const routes = [];
1724
+ const visited = /* @__PURE__ */ new WeakSet();
1725
+ const seenPaths = /* @__PURE__ */ new Set();
1726
+ function traverse$1(node) {
1727
+ if (!node || visited.has(node)) return;
1728
+ visited.add(node);
1729
+ const props = node.memoizedProps || node.pendingProps;
1730
+ if (isRouteContextProvider(node)) {
1731
+ const match = props.value.match;
1732
+ const path = match.path || match.url || "/";
1733
+ if (!seenPaths.has(path)) {
1734
+ seenPaths.add(path);
1735
+ const routeInfo = {
1736
+ path,
1737
+ params: match.params ? Object.keys(match.params) : void 0,
1738
+ exact: match.isExact
1739
+ };
1740
+ if (node.child) {
1741
+ const childName = getDisplayName(node.child);
1742
+ if (childName && childName !== "Anonymous" && childName.length > 1) routeInfo.element = childName;
1743
+ }
1744
+ routes.push(routeInfo);
1745
+ }
1746
+ }
1747
+ if (props === null || props === void 0 ? void 0 : props.children) {
1748
+ const children = Array.isArray(props.children) ? props.children : [props.children];
1749
+ let hasRouteChildren = false;
1750
+ for (const child of children) if (child && child.props && isLikelyV5Route(child.props)) {
1751
+ hasRouteChildren = true;
1752
+ const route = extractRouteFromElementV5(child);
1753
+ if (route && !seenPaths.has(route.path)) {
1754
+ seenPaths.add(route.path);
1755
+ routes.push(route);
1756
+ }
1757
+ }
1758
+ if (hasRouteChildren) return;
1759
+ }
1760
+ if (node.child) traverse$1(node.child);
1761
+ if (node.sibling) traverse$1(node.sibling);
1762
+ }
1763
+ traverse$1(fiber);
1764
+ return routes;
1765
+ }
1766
+ /**
1669
1767
  * Extract route info from a React Router v5 Route element (JSX props)
1670
1768
  */
1671
1769
  function extractRouteFromElementV5(element, parentPath = "") {
@@ -1678,13 +1776,16 @@ function extractRouteFromElementV5(element, parentPath = "") {
1678
1776
  const childRoutes = [];
1679
1777
  if (props.children && typeof props.children !== "function") {
1680
1778
  const children = Array.isArray(props.children) ? props.children : [props.children];
1681
- for (const child of children) {
1682
- var _child$type3, _child$type4;
1683
- if (child && child.type && (child.type.name === "Route" || ((_child$type3 = child.type) === null || _child$type3 === void 0 ? void 0 : _child$type3.displayName) === "Route")) {
1779
+ for (const child of children) if (child && child.type) {
1780
+ var _child$type3;
1781
+ const typeName = child.type.name || ((_child$type3 = child.type) === null || _child$type3 === void 0 ? void 0 : _child$type3.displayName);
1782
+ const isRoute = typeName === "Route" || isLikelyV5Route(child.props);
1783
+ const isSwitch = typeName === "Switch" || isLikelyV5Switch(child.props);
1784
+ const isRedirect = typeName === "Redirect" || isLikelyV5Redirect(child.props);
1785
+ if (isRoute && !isRedirect) {
1684
1786
  const childRoute = extractRouteFromElementV5(child, fullPath);
1685
1787
  if (childRoute) childRoutes.push(childRoute);
1686
- }
1687
- if (child && child.type && (child.type.name === "Switch" || ((_child$type4 = child.type) === null || _child$type4 === void 0 ? void 0 : _child$type4.displayName) === "Switch")) {
1788
+ } else if (isSwitch) {
1688
1789
  const switchChildren = extractRoutesFromSwitchProps(child.props, fullPath);
1689
1790
  childRoutes.push(...switchChildren);
1690
1791
  }
@@ -1712,15 +1813,18 @@ function extractRoutesFromSwitchProps(props, parentPath = "") {
1712
1813
  const children = Array.isArray(props.children) ? props.children : [props.children];
1713
1814
  for (const child of children) if (child && child.type) {
1714
1815
  const typeName = child.type.name || child.type.displayName;
1715
- if (typeName === "Route") {
1816
+ const isRoute = typeName === "Route" || isLikelyV5Route(child.props);
1817
+ const isRedirect = typeName === "Redirect" || isLikelyV5Redirect(child.props);
1818
+ if (isRoute && !isRedirect) {
1716
1819
  const route = extractRouteFromElementV5(child, parentPath);
1717
1820
  if (route) routes.push(route);
1718
- }
1719
- if (typeName === "Redirect") {
1821
+ } else if (isRedirect) {
1720
1822
  var _child$props, _child$props2, _child$props3;
1823
+ const to = (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.to;
1824
+ const toPath = typeof to === "string" ? to : (to === null || to === void 0 ? void 0 : to.pathname) || "unknown";
1721
1825
  const redirectInfo = {
1722
- path: ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.from) || "*",
1723
- element: `Redirect → ${((_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : _child$props2.to) || "unknown"}`,
1826
+ path: ((_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : _child$props2.from) || "*",
1827
+ element: `Redirect → ${toPath}`,
1724
1828
  exact: ((_child$props3 = child.props) === null || _child$props3 === void 0 ? void 0 : _child$props3.exact) === true
1725
1829
  };
1726
1830
  routes.push(redirectInfo);
@@ -1781,7 +1885,7 @@ function findAndExtractRoutes(fiber) {
1781
1885
  return;
1782
1886
  }
1783
1887
  }
1784
- if (name === "Switch") {
1888
+ if (name === "Switch" || isLikelyV5Switch(props)) {
1785
1889
  const switchRoutes = extractRoutesFromSwitchProps(props);
1786
1890
  if (switchRoutes.length > 0) {
1787
1891
  routes = switchRoutes;
@@ -1796,6 +1900,7 @@ function findAndExtractRoutes(fiber) {
1796
1900
  if (node.sibling) traverse$1(node.sibling);
1797
1901
  }
1798
1902
  traverse$1(fiber);
1903
+ if (routes.length === 0) routes = extractRoutesFromFiberV5(fiber);
1799
1904
  return routes;
1800
1905
  }
1801
1906
  /**
@@ -1903,7 +2008,10 @@ function detectRouterType(fiber) {
1903
2008
  if (!node || visited.has(node)) return null;
1904
2009
  visited.add(node);
1905
2010
  const name = getDisplayName(node);
2011
+ const props = node.memoizedProps || node.pendingProps;
1906
2012
  if (name === "Router" || name === "BrowserRouter" || name === "HashRouter" || name === "MemoryRouter" || name === "Routes" || name === "Switch" || name === "Route") return "react-router";
2013
+ if (isLikelyV5Switch(props) || isLikelyV5Route(props)) return "react-router";
2014
+ if (isRouterContextProvider(node) || isRouteContextProvider(node)) return "react-router";
1907
2015
  if (node.child) {
1908
2016
  const result = traverse$1(node.child);
1909
2017
  if (result) return result;
package/dist/index.js CHANGED
@@ -1642,6 +1642,104 @@ function getV5ComponentName(props) {
1642
1642
  if (typeof props.children === "function") return "children()";
1643
1643
  }
1644
1644
  /**
1645
+ * Check if a component is likely a React Router v5 Route by its props
1646
+ */
1647
+ function isLikelyV5Route(props) {
1648
+ if (!props) return false;
1649
+ const hasPath = typeof props.path === "string" || props.path === void 0;
1650
+ const hasRouteProps = props.component || props.render || props.children !== void 0;
1651
+ const hasExactOrStrict = props.exact !== void 0 || props.strict !== void 0;
1652
+ const hasLocation = props.location !== void 0;
1653
+ const hasComputedMatch = props.computedMatch !== void 0;
1654
+ return hasPath && hasRouteProps || hasExactOrStrict || hasComputedMatch || hasLocation;
1655
+ }
1656
+ /**
1657
+ * Check if a component is likely a React Router v5 Switch by its props/children
1658
+ */
1659
+ function isLikelyV5Switch(props) {
1660
+ if (!props || !props.children) return false;
1661
+ const children = Array.isArray(props.children) ? props.children : [props.children];
1662
+ for (const child of children) if (child && child.props) {
1663
+ if (isLikelyV5Route(child.props)) return true;
1664
+ }
1665
+ return false;
1666
+ }
1667
+ /**
1668
+ * Check if a component is likely a React Router v5 Redirect by its props
1669
+ */
1670
+ function isLikelyV5Redirect(props) {
1671
+ if (!props) return false;
1672
+ return typeof props.to === "string" || typeof props.to === "object" && props.to !== null;
1673
+ }
1674
+ /**
1675
+ * Check if a fiber node is a React Router v5 context provider
1676
+ * React Router v5 uses __RouterContext with value containing { history, location, match, staticContext }
1677
+ */
1678
+ function isRouterContextProvider(fiber) {
1679
+ const props = fiber.memoizedProps || fiber.pendingProps;
1680
+ if (!(props === null || props === void 0 ? void 0 : props.value)) return false;
1681
+ const value = props.value;
1682
+ return !!(value.history && value.location && typeof value.match === "object");
1683
+ }
1684
+ /**
1685
+ * Check if a fiber node is a React Router v5 Route context provider
1686
+ * Route wraps children in a context provider with match info
1687
+ */
1688
+ function isRouteContextProvider(fiber) {
1689
+ const props = fiber.memoizedProps || fiber.pendingProps;
1690
+ if (!(props === null || props === void 0 ? void 0 : props.value)) return false;
1691
+ const value = props.value;
1692
+ return !!(value.match && typeof value.match.path === "string");
1693
+ }
1694
+ /**
1695
+ * Extract routes from React Router v5 by traversing fiber tree and finding Route context providers
1696
+ * This works even when component names are minified
1697
+ */
1698
+ function extractRoutesFromFiberV5(fiber) {
1699
+ const routes = [];
1700
+ const visited = /* @__PURE__ */ new WeakSet();
1701
+ const seenPaths = /* @__PURE__ */ new Set();
1702
+ function traverse$1(node) {
1703
+ if (!node || visited.has(node)) return;
1704
+ visited.add(node);
1705
+ const props = node.memoizedProps || node.pendingProps;
1706
+ if (isRouteContextProvider(node)) {
1707
+ const match = props.value.match;
1708
+ const path = match.path || match.url || "/";
1709
+ if (!seenPaths.has(path)) {
1710
+ seenPaths.add(path);
1711
+ const routeInfo = {
1712
+ path,
1713
+ params: match.params ? Object.keys(match.params) : void 0,
1714
+ exact: match.isExact
1715
+ };
1716
+ if (node.child) {
1717
+ const childName = getDisplayName(node.child);
1718
+ if (childName && childName !== "Anonymous" && childName.length > 1) routeInfo.element = childName;
1719
+ }
1720
+ routes.push(routeInfo);
1721
+ }
1722
+ }
1723
+ if (props === null || props === void 0 ? void 0 : props.children) {
1724
+ const children = Array.isArray(props.children) ? props.children : [props.children];
1725
+ let hasRouteChildren = false;
1726
+ for (const child of children) if (child && child.props && isLikelyV5Route(child.props)) {
1727
+ hasRouteChildren = true;
1728
+ const route = extractRouteFromElementV5(child);
1729
+ if (route && !seenPaths.has(route.path)) {
1730
+ seenPaths.add(route.path);
1731
+ routes.push(route);
1732
+ }
1733
+ }
1734
+ if (hasRouteChildren) return;
1735
+ }
1736
+ if (node.child) traverse$1(node.child);
1737
+ if (node.sibling) traverse$1(node.sibling);
1738
+ }
1739
+ traverse$1(fiber);
1740
+ return routes;
1741
+ }
1742
+ /**
1645
1743
  * Extract route info from a React Router v5 Route element (JSX props)
1646
1744
  */
1647
1745
  function extractRouteFromElementV5(element, parentPath = "") {
@@ -1654,13 +1752,16 @@ function extractRouteFromElementV5(element, parentPath = "") {
1654
1752
  const childRoutes = [];
1655
1753
  if (props.children && typeof props.children !== "function") {
1656
1754
  const children = Array.isArray(props.children) ? props.children : [props.children];
1657
- for (const child of children) {
1658
- var _child$type3, _child$type4;
1659
- if (child && child.type && (child.type.name === "Route" || ((_child$type3 = child.type) === null || _child$type3 === void 0 ? void 0 : _child$type3.displayName) === "Route")) {
1755
+ for (const child of children) if (child && child.type) {
1756
+ var _child$type3;
1757
+ const typeName = child.type.name || ((_child$type3 = child.type) === null || _child$type3 === void 0 ? void 0 : _child$type3.displayName);
1758
+ const isRoute = typeName === "Route" || isLikelyV5Route(child.props);
1759
+ const isSwitch = typeName === "Switch" || isLikelyV5Switch(child.props);
1760
+ const isRedirect = typeName === "Redirect" || isLikelyV5Redirect(child.props);
1761
+ if (isRoute && !isRedirect) {
1660
1762
  const childRoute = extractRouteFromElementV5(child, fullPath);
1661
1763
  if (childRoute) childRoutes.push(childRoute);
1662
- }
1663
- if (child && child.type && (child.type.name === "Switch" || ((_child$type4 = child.type) === null || _child$type4 === void 0 ? void 0 : _child$type4.displayName) === "Switch")) {
1764
+ } else if (isSwitch) {
1664
1765
  const switchChildren = extractRoutesFromSwitchProps(child.props, fullPath);
1665
1766
  childRoutes.push(...switchChildren);
1666
1767
  }
@@ -1688,15 +1789,18 @@ function extractRoutesFromSwitchProps(props, parentPath = "") {
1688
1789
  const children = Array.isArray(props.children) ? props.children : [props.children];
1689
1790
  for (const child of children) if (child && child.type) {
1690
1791
  const typeName = child.type.name || child.type.displayName;
1691
- if (typeName === "Route") {
1792
+ const isRoute = typeName === "Route" || isLikelyV5Route(child.props);
1793
+ const isRedirect = typeName === "Redirect" || isLikelyV5Redirect(child.props);
1794
+ if (isRoute && !isRedirect) {
1692
1795
  const route = extractRouteFromElementV5(child, parentPath);
1693
1796
  if (route) routes.push(route);
1694
- }
1695
- if (typeName === "Redirect") {
1797
+ } else if (isRedirect) {
1696
1798
  var _child$props, _child$props2, _child$props3;
1799
+ const to = (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.to;
1800
+ const toPath = typeof to === "string" ? to : (to === null || to === void 0 ? void 0 : to.pathname) || "unknown";
1697
1801
  const redirectInfo = {
1698
- path: ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.from) || "*",
1699
- element: `Redirect → ${((_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : _child$props2.to) || "unknown"}`,
1802
+ path: ((_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : _child$props2.from) || "*",
1803
+ element: `Redirect → ${toPath}`,
1700
1804
  exact: ((_child$props3 = child.props) === null || _child$props3 === void 0 ? void 0 : _child$props3.exact) === true
1701
1805
  };
1702
1806
  routes.push(redirectInfo);
@@ -1757,7 +1861,7 @@ function findAndExtractRoutes(fiber) {
1757
1861
  return;
1758
1862
  }
1759
1863
  }
1760
- if (name === "Switch") {
1864
+ if (name === "Switch" || isLikelyV5Switch(props)) {
1761
1865
  const switchRoutes = extractRoutesFromSwitchProps(props);
1762
1866
  if (switchRoutes.length > 0) {
1763
1867
  routes = switchRoutes;
@@ -1772,6 +1876,7 @@ function findAndExtractRoutes(fiber) {
1772
1876
  if (node.sibling) traverse$1(node.sibling);
1773
1877
  }
1774
1878
  traverse$1(fiber);
1879
+ if (routes.length === 0) routes = extractRoutesFromFiberV5(fiber);
1775
1880
  return routes;
1776
1881
  }
1777
1882
  /**
@@ -1879,7 +1984,10 @@ function detectRouterType(fiber) {
1879
1984
  if (!node || visited.has(node)) return null;
1880
1985
  visited.add(node);
1881
1986
  const name = getDisplayName(node);
1987
+ const props = node.memoizedProps || node.pendingProps;
1882
1988
  if (name === "Router" || name === "BrowserRouter" || name === "HashRouter" || name === "MemoryRouter" || name === "Routes" || name === "Switch" || name === "Route") return "react-router";
1989
+ if (isLikelyV5Switch(props) || isLikelyV5Route(props)) return "react-router";
1990
+ if (isRouterContextProvider(node) || isRouteContextProvider(node)) return "react-router";
1883
1991
  if (node.child) {
1884
1992
  const result = traverse$1(node.child);
1885
1993
  if (result) return result;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@react-devtools-plus/kit",
3
3
  "type": "module",
4
- "version": "0.9.5",
4
+ "version": "0.9.6",
5
5
  "author": "wzc520pyfm",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "mitt": "^3.0.1",
28
28
  "perfect-debounce": "^2.0.0",
29
29
  "superjson": "^2.2.2",
30
- "@react-devtools-plus/shared": "^0.9.5"
30
+ "@react-devtools-plus/shared": "^0.9.6"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^24.7.2",