@@ -58,6 +58,7 @@ const useCustomMenuItems = ({
5858 const validChildren : CustomMenuItemType [ ] = [ ] ;
5959 const customMenuItems : CustomMenuItem [ ] = [ ] ;
6060 const customMenuItemsPortals : React . ComponentType [ ] = [ ] ;
61+ const portalIdCounts = new Map < string , number > ( ) ;
6162
6263 React . Children . forEach ( children , child => {
6364 if (
@@ -107,13 +108,13 @@ const useCustomMenuItems = ({
107108 validChildren . push ( {
108109 ...baseItem ,
109110 onClick,
110- portalId : getCustomMenuItemPortalId ( 'action' , props , childKey ) ,
111+ portalId : getCustomMenuItemPortalId ( 'action' , props , childKey , portalIdCounts ) ,
111112 } ) ;
112113 } else if ( open !== undefined ) {
113114 validChildren . push ( {
114115 ...baseItem ,
115116 open : open . startsWith ( '/' ) ? open : `/${ open } ` ,
116- portalId : getCustomMenuItemPortalId ( 'action' , props , childKey ) ,
117+ portalId : getCustomMenuItemPortalId ( 'action' , props , childKey , portalIdCounts ) ,
117118 } ) ;
118119 } else {
119120 // Handle the case where neither onClick nor open is defined
@@ -128,7 +129,12 @@ const useCustomMenuItems = ({
128129
129130 if ( isThatComponent ( child , MenuLinkComponent ) ) {
130131 if ( isExternalLink ( props ) ) {
131- validChildren . push ( { label, labelIcon, href, portalId : getCustomMenuItemPortalId ( 'link' , props , childKey ) } ) ;
132+ validChildren . push ( {
133+ label,
134+ labelIcon,
135+ href,
136+ portalId : getCustomMenuItemPortalId ( 'link' , props , childKey , portalIdCounts ) ,
137+ } ) ;
132138 } else {
133139 logErrorInDevMode ( userButtonMenuItemLinkWrongProps ) ;
134140 return ;
@@ -200,13 +206,17 @@ const getCustomMenuItemPortalId = (
200206 type : 'action' | 'link' ,
201207 props : Pick < CustomMenuItemType , 'label' > & { href ?: string ; open ?: string } ,
202208 key : React . Key | null ,
209+ portalIdCounts : Map < string , number > ,
203210) => {
204211 if ( key != null ) {
205212 return `${ type } :key:${ key } ` ;
206213 }
207214
208215 const target = props . href || props . open || '' ;
209- return `${ type } :${ props . label } :${ target } ` ;
216+ const baseId = `${ type } :${ props . label } :${ target } ` ;
217+ const occurrence = portalIdCounts . get ( baseId ) ?? 0 ;
218+ portalIdCounts . set ( baseId , occurrence + 1 ) ;
219+ return `${ baseId } :${ occurrence } ` ;
210220} ;
211221
212222const isReorderItem = ( childProps : any , validItems : string [ ] ) : boolean => {
0 commit comments