`'s routes in the shared set for as long as it is mounted, removing them on + // unmount so they don't leak into later unrelated navigations (#22782). Tying add and remove to the + // same effect lifecycle keeps it correct under StrictMode's mount/unmount/remount. + useIsomorphicLayoutEffect(() => { + const added = addRoutesToAllRoutes(routes); + + return () => removeRoutesFromAllRoutes(added); + }); + useIsomorphicLayoutEffect( () => { - const routes = _createRoutesFromChildren(props.children) as RouteObject[]; - if (isMountRenderPass.current) { - addRoutesToAllRoutes(routes); - updatePageloadTransaction({ activeRootSpan: getActiveRootSpan(), location,