22
33import { cn } from "@/lib/utils" ;
44import Link from "next/link" ;
5+ import { usePathname } from "next/navigation" ;
56import { useEffect , useRef , useState } from "react" ;
67
78/**
@@ -29,6 +30,7 @@ export function TableOfContentsSideBar(props: {
2930} ) {
3031 const [ nodes , setNodes ] = useState < TableOfContentNode [ ] > ( [ ] ) ;
3132 const tocRef = useRef < HTMLDivElement > ( null ) ;
33+ const pathname = usePathname ( ) ;
3234
3335 const [ hideNav , setHideNav ] = useState ( false ) ;
3436 const { filterHeading } = props ;
@@ -45,6 +47,9 @@ export function TableOfContentsSideBar(props: {
4547 root . querySelectorAll ( "a[href^='#']" ) ,
4648 ) as HTMLAnchorElement [ ] ;
4749
50+ // using pathname to fix exhaustive dependency lint warning without suppressing it entirely
51+ tocRef . current ?. setAttribute ( "data-pathname" , pathname ) ;
52+
4853 // hide anchors inside hidden elements
4954 const anchors = anchorsAll . filter ( ( anchor ) => {
5055 return anchor . closest ( "[data-collapsible]" ) === null ;
@@ -104,7 +109,7 @@ export function TableOfContentsSideBar(props: {
104109 return ( ) => {
105110 observer . disconnect ( ) ;
106111 } ;
107- } , [ filterHeading ] ) ;
112+ } , [ filterHeading , pathname ] ) ;
108113
109114 return (
110115 < nav
0 commit comments