1- import { type MouseEvent , useEffect , useState } from "react"
1+ import { type MouseEvent , useCallback , useEffect , useMemo , useState } from "react"
22import { useMatches , useNavigate } from "react-router"
33import { eventClient } from "../../shared/event-client.js"
44import { Accordion , AccordionContent , AccordionItem , AccordionTrigger } from "../components/Accordion.js"
@@ -19,17 +19,23 @@ const RoutesTab = () => {
1919 const { styles } = useStyles ( )
2020 const matches = useMatches ( )
2121 const navigate = useNavigate ( )
22- const activeRoutes = matches . map ( ( match ) => match . id )
22+ // Memoize active routes to avoid recreating array on every render
23+ const activeRoutes = useMemo ( ( ) => matches . map ( ( match ) => match . id ) , [ matches ] )
2324 const { settings } = useSettingsContext ( )
2425 const { routeWildcards, routeViewMode } = settings
2526 const [ activeRoute , setActiveRoute ] = useState < ExtendedRoute | null > ( null )
2627 const [ routes , setRoutes ] = useState < ExtendedRoute [ ] > ( createExtendedRoutes ( ) as ExtendedRoute [ ] )
2728 const [ treeRoutes , setTreeRoutes ] = useState ( createRouteTree ( window . __reactRouterManifest ?. routes ) )
2829 const isTreeView = routeViewMode === "tree"
29- const openNewRoute = ( path : string ) => ( e ?: MouseEvent < HTMLDivElement | HTMLButtonElement > ) => {
30- e ?. preventDefault ( )
31- navigate ( path )
32- }
30+
31+ // Memoize openNewRoute callback to prevent recreating on every render
32+ const openNewRoute = useCallback (
33+ ( path : string ) => ( e ?: MouseEvent < HTMLDivElement | HTMLButtonElement > ) => {
34+ e ?. preventDefault ( )
35+ navigate ( path )
36+ } ,
37+ [ navigate ]
38+ )
3339
3440 useEffect ( function fetchAllRoutesOnMount ( ) {
3541 // Listen for routes info response from the server FIRST
0 commit comments