Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the annoying key duplication warning #743

Open
voltuer opened this issue Dec 12, 2024 · 0 comments
Open

remove the annoying key duplication warning #743

voltuer opened this issue Dec 12, 2024 · 0 comments

Comments

@voltuer
Copy link

voltuer commented Dec 12, 2024

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/rc-menu/es/hooks/useKeyRecords.js b/node_modules/rc-menu/es/hooks/useKeyRecords.js
index 1afe5c8..d09e433 100644
--- a/node_modules/rc-menu/es/hooks/useKeyRecords.js
+++ b/node_modules/rc-menu/es/hooks/useKeyRecords.js
@@ -1,17 +1,17 @@
 import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
 import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
-import * as React from 'react';
-import { useRef, useCallback } from 'react';
+import * as React from "react";
+import { useRef, useCallback } from "react";
 import warning from "rc-util/es/warning";
 import { nextSlice } from "../utils/timeUtil";
-var PATH_SPLIT = '__RC_UTIL_PATH_SPLIT__';
+var PATH_SPLIT = "__RC_UTIL_PATH_SPLIT__";
 var getPathStr = function getPathStr(keyPath) {
   return keyPath.join(PATH_SPLIT);
 };
 var getPathKeys = function getPathKeys(keyPathStr) {
   return keyPathStr.split(PATH_SPLIT);
 };
-export var OVERFLOW_KEY = 'rc-menu-more';
+export var OVERFLOW_KEY = "rc-menu-more";
 export default function useKeyRecords() {
   var _React$useState = React.useState({}),
     _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -31,9 +31,9 @@ export default function useKeyRecords() {
   };
   var registerPath = useCallback(function (key, keyPath) {
     // Warning for invalidate or duplicated `key`
-    if (process.env.NODE_ENV !== 'production') {
-      warning(!key2pathRef.current.has(key), "Duplicated key '".concat(key, "' used in Menu by path [").concat(keyPath.join(' > '), "]"));
-    }
+    // if (process.env.NODE_ENV !== 'production') {
+    //   warning(!key2pathRef.current.has(key), "Duplicated key '".concat(key, "' used in Menu by path [").concat(keyPath.join(' > '), "]"));
+    // }
 
     // Fill map
     var connectedPath = getPathStr(keyPath);
@@ -55,22 +55,30 @@ export default function useKeyRecords() {
   var refreshOverflowKeys = useCallback(function (keys) {
     setOverflowKeys(keys);
   }, []);
-  var getKeyPath = useCallback(function (eventKey, includeOverflow) {
-    var fullPath = key2pathRef.current.get(eventKey) || '';
-    var keys = getPathKeys(fullPath);
-    if (includeOverflow && overflowKeys.includes(keys[0])) {
-      keys.unshift(OVERFLOW_KEY);
-    }
-    return keys;
-  }, [overflowKeys]);
-  var isSubPathKey = useCallback(function (pathKeys, eventKey) {
-    return pathKeys.filter(function (item) {
-      return item !== undefined;
-    }).some(function (pathKey) {
-      var pathKeyList = getKeyPath(pathKey, true);
-      return pathKeyList.includes(eventKey);
-    });
-  }, [getKeyPath]);
+  var getKeyPath = useCallback(
+    function (eventKey, includeOverflow) {
+      var fullPath = key2pathRef.current.get(eventKey) || "";
+      var keys = getPathKeys(fullPath);
+      if (includeOverflow && overflowKeys.includes(keys[0])) {
+        keys.unshift(OVERFLOW_KEY);
+      }
+      return keys;
+    },
+    [overflowKeys],
+  );
+  var isSubPathKey = useCallback(
+    function (pathKeys, eventKey) {
+      return pathKeys
+        .filter(function (item) {
+          return item !== undefined;
+        })
+        .some(function (pathKey) {
+          var pathKeyList = getKeyPath(pathKey, true);
+          return pathKeyList.includes(eventKey);
+        });
+    },
+    [getKeyPath],
+  );
   var getKeys = function getKeys() {
     var keys = _toConsumableArray(key2pathRef.current.keys());
     if (overflowKeys.length) {
@@ -83,7 +91,9 @@ export default function useKeyRecords() {
    * Find current key related child path keys
    */
   var getSubPathKeys = useCallback(function (key) {
-    var connectedPath = "".concat(key2pathRef.current.get(key)).concat(PATH_SPLIT);
+    var connectedPath = ""
+      .concat(key2pathRef.current.get(key))
+      .concat(PATH_SPLIT);
     var pathKeys = new Set();
     _toConsumableArray(path2keyRef.current.keys()).forEach(function (pathKey) {
       if (pathKey.startsWith(connectedPath)) {
@@ -106,6 +116,6 @@ export default function useKeyRecords() {
     isSubPathKey: isSubPathKey,
     getKeyPath: getKeyPath,
     getKeys: getKeys,
-    getSubPathKeys: getSubPathKeys
+    getSubPathKeys: getSubPathKeys,
   };
 }

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant