docs: fix sidebar not updating when api reference path changes (#8409)
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
import {
|
||||
SidebarProvider as UiSidebarProvider,
|
||||
usePageLoading,
|
||||
usePrevious,
|
||||
useScrollController,
|
||||
} from "docs-ui"
|
||||
import { config } from "../config"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useCallback } from "react"
|
||||
|
||||
type SidebarProviderProps = {
|
||||
children?: React.ReactNode
|
||||
@@ -13,6 +16,13 @@ type SidebarProviderProps = {
|
||||
const SidebarProvider = ({ children }: SidebarProviderProps) => {
|
||||
const { isLoading, setIsLoading } = usePageLoading()
|
||||
const { scrollableElement } = useScrollController()
|
||||
const pathname = usePathname()
|
||||
const prevPathname = usePrevious(pathname)
|
||||
|
||||
const resetOnCondition = useCallback(
|
||||
() => prevPathname !== undefined && prevPathname !== pathname,
|
||||
[pathname, prevPathname]
|
||||
)
|
||||
|
||||
return (
|
||||
<UiSidebarProvider
|
||||
@@ -21,6 +31,7 @@ const SidebarProvider = ({ children }: SidebarProviderProps) => {
|
||||
shouldHandleHashChange={true}
|
||||
scrollableElement={scrollableElement}
|
||||
initialItems={config.sidebar}
|
||||
resetOnCondition={resetOnCondition}
|
||||
>
|
||||
{children}
|
||||
</UiSidebarProvider>
|
||||
|
||||
Reference in New Issue
Block a user