Skip to content

Commit

Permalink
docs: fix current sidebar not found (#11155)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Jan 25, 2025
1 parent f803157 commit 1d7eeb5
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions www/packages/docs-ui/src/providers/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,19 @@ export const isSidebarItemLink = (
)
}

const areItemsEqual = (itemA: SidebarItem, itemB: SidebarItem): boolean => {
const areItemsEqual = (
itemA: SidebarItem,
itemB: SidebarItem,
compareTitles = true
): boolean => {
if (
itemA.type === "separator" ||
itemB.type === "separator" ||
itemA.type !== itemB.type
) {
return false
}
const hasSameTitle = itemA.title === itemB.title
const hasSameTitle = !compareTitles || itemA.title === itemB.title
const hasSamePath =
!isSidebarItemLink(itemA) ||
!isSidebarItemLink(itemB) ||
Expand All @@ -127,17 +131,18 @@ const areItemsEqual = (itemA: SidebarItem, itemB: SidebarItem): boolean => {
const findItem = (
section: SidebarItem[],
item: Partial<SidebarItem>,
checkChildren = true
checkChildren = true,
compareTitles = true
): SidebarItemLinkWithParent | undefined => {
let foundItem: SidebarItemLinkWithParent | undefined
section.some((i) => {
if (i.type === "separator") {
return false
}
if (areItemsEqual(item as SidebarItem, i)) {
if (areItemsEqual(item as SidebarItem, i, compareTitles)) {
foundItem = i as SidebarItemLink
} else if (checkChildren && i.children) {
foundItem = findItem(i.children, item)
foundItem = findItem(i.children, item, checkChildren, compareTitles)
if (foundItem && !foundItem.parentItem) {
foundItem.parentItem = i
}
Expand Down Expand Up @@ -428,10 +433,15 @@ export const SidebarProvider = ({
const childSidebar =
getCurrentSidebar(item.children) ||
(activePath
? findItem(item.children, {
path: activePath,
type: "link",
})
? findItem(
item.children,
{
path: activePath,
type: "link",
},
true,
false
)
: undefined)

currentSidebar = childSidebar
Expand Down

0 comments on commit 1d7eeb5

Please sign in to comment.