@@ -16,6 +16,7 @@ import s from "./styles.module.scss";
1616
1717import type { SidebarCategory as SidebarCategoryType , SidebarDoc as SidebarDocType , SidebarItem as SidebarItemType } from "@/lib/helpers/sidebar" ;
1818import type { SidebarProps } from "." ;
19+ import { canUseDOM } from "@/utils/environment" ;
1920
2021interface SidebarItemProps extends Omit < SidebarProps , 'items' > , React . AnchorHTMLAttributes < HTMLAnchorElement > {
2122 item : SidebarItemType
@@ -32,18 +33,19 @@ const SidebarCategory = ({ item, activePath, ...props }: SidebarItemProps): JSX.
3233 const { items, label, href } = item as SidebarCategoryType ;
3334
3435 const isActive = isActiveSidebarItem ( item , activePath ) ;
35- const { collapsed, toggleCollapsed } = useCollapsible ( ! isActive ) ;
36+ const { collapsed, toggleCollapsed } = useCollapsible ( ! canUseDOM ? true : ! isActive ) ;
3637
3738 return (
3839 < li >
3940 < div className = { s . category } >
40- { /* given we have sidebar, could instead just make these buttons that collapse the category maybe? */ }
41+ { /* TODO: given we have sidebar, could instead just make these buttons that collapse the category maybe? */ }
4142 < Link href = { href } > < a
4243 className = { c ( s . link , isActive && s . active ) }
44+ // TODO: fix SSR error here
4345 aria-expanded = { ! collapsed }
44- >
45- { label }
46- </ a > </ Link >
46+ // we construct the label from our locally sourced files so we can assume it's safe
47+ dangerouslySetInnerHTML = { { __html : label } }
48+ / ></ Link >
4749 < button
4850 className = { c ( s . arrow , collapsed && s . collapsed ) }
4951 aria-label = { `toggle the sidebar category '${ label } '` }
@@ -71,7 +73,7 @@ const SidebarCategory = ({ item, activePath, ...props }: SidebarItemProps): JSX.
7173}
7274
7375const SidebarDoc = ( { item, activePath, ...props } : SidebarItemProps ) => {
74- const { href, title } = item as SidebarDocType ;
76+ const { href, label } = item as SidebarDocType ;
7577 const isActive = isActiveSidebarItem ( item , activePath ) ;
7678
7779 return (
@@ -81,10 +83,10 @@ const SidebarDoc = ({ item, activePath, ...props }: SidebarItemProps) => {
8183 s . link ,
8284 isActive && s . active ,
8385 ) }
86+ // we construct the label from our locally sourced files so we can assume it's safe
87+ dangerouslySetInnerHTML = { { __html : label } }
8488 { ...props }
85- >
86- { title }
87- </ a > </ Link >
89+ /> </ Link >
8890 </ li >
8991 )
9092}
0 commit comments