Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
fix(docs): Fix sidebar highlighting (#86)
Pavel 'Strajk' Dolecek5d4cbd1dc877
diff --git a/apps/docs/src/components/Navigation.tsx b/apps/docs/src/components/Navigation.tsxindex 4e42de37b..7db6e26aa 100644--- a/apps/docs/src/components/Navigation.tsx+++ b/apps/docs/src/components/Navigation.tsx@@ -103,10 +103,8 @@ function VisibleSectionHighlight({ group, pathname }) {let height = isPresent? Math.max(1, visibleSections.length) * itemHeight: itemHeight- let top =- group.links.findIndex((link) => `/docs${link.href}` === pathname) *- itemHeight +- firstVisibleSectionIndex * itemHeight+ let activePageIndex = activeGroupIndex(group, pathname)+ let top = activePageIndex * itemHeight + firstVisibleSectionIndex * itemHeightreturn (<motion.div@@ -129,9 +127,7 @@ function ActivePageMarker({}) {let itemHeight = remToPx(2)let offset = remToPx(0.25)- let activePageIndex = group.links.findIndex(- (link) => `/docs${link.href}` === pathname- )+ let activePageIndex = activeGroupIndex(group, pathname)let top = offset + activePageIndex * itemHeightreturn (@@ -151,14 +147,18 @@ function NavigationGroup({ group, className }) {// state, so that the state does not change during the close animation.// The state will still update when we re-open (re-render) the navigation.let isInsideMobileNavigation = useIsInsideMobileNavigation()+ let initialPathname = usePathname();++ // Running on the server, there's bug with usePathname() and basePath https://github.com/vercel/next.js/issues/52700+ if (typeof window === 'undefined' && initialPathname === '/') initialPathname = '/docs'+let [pathname, sections] = useInitialValue(- [usePathname(), useSectionStore((s) => s.sections)],+ [initialPathname, useSectionStore((s) => s.sections)],isInsideMobileNavigation)-- let isActiveGroup =- group.links.findIndex((link) => `/docs${link.href}` === pathname) !== -1-++ let isActiveGroup = activeGroupIndex(group, pathname) !== -1+return (<li className={clsx('relative mt-6', className)}><motion.h2@@ -342,3 +342,10 @@ export function Navigation(props) {</nav>)}++function activeGroupIndex(group: NavGroup, pathname: string) {+ return group.links.findIndex((link) => {+ if (link.href === `/` && pathname === `/docs`) return true // special case for index+ return `/docs${link.href}` === pathname+ })+}