Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

remove the annoying key duplication warning

Aperta
#743 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, react, typescript
Ambito
frontend

Direzione di ricerca

Inizia individuando il codice sorgente corrispondente a node_modules/rc-menu/es/hooks/useKeyRecords.js e l’avviso esistente relativo alle chiavi duplicate. Confronta il diff segnalato con il codice sorgente e i test del repository; il lavoro è completato quando il comportamento dell’avviso viene modificato intenzionalmente senza modificare i file delle dipendenze generati, con una copertura per le chiavi di menu interessate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
701
Fork
266
Merge medio
1g 9h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di react-component/menu

Tutte le issue di react-component/menu

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.