Skip to content

Commit 30ee17e

Browse files
committed
feat: remove blinking sidebar
1 parent 496de84 commit 30ee17e

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

apps/docs/src/components/sidebar.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ interface SidebarProps {
88
currentPath: string
99
}
1010

11-
export function Sidebar({ items, currentPath }: SidebarProps) {
11+
export function Sidebar({ items, currentPath: initialPath }: SidebarProps) {
12+
const [currentPath, setCurrentPath] = React.useState(initialPath)
13+
14+
React.useEffect(() => {
15+
const handleSwap = () => setCurrentPath(window.location.pathname)
16+
document.addEventListener('astro:after-swap', handleSwap)
17+
return () => document.removeEventListener('astro:after-swap', handleSwap)
18+
}, [])
19+
1220
return (
1321
<nav className="flex-1 overflow-y-auto">
1422
<ul>
@@ -28,6 +36,12 @@ function SidebarItem({ item, currentPath, depth = 0 }: { item: NavItem; currentP
2836
return false
2937
})
3038

39+
React.useEffect(() => {
40+
if (item.type === 'category') {
41+
setOpen(isActiveCategory(item, currentPath))
42+
}
43+
}, [currentPath, item])
44+
3145
// Group: bold label, no collapse, children always visible, depth resets
3246
if (item.type === 'group') {
3347
return (

apps/docs/src/layouts/docs.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const appUrlOverrides = {
127127
transition:animate="none"
128128
/>
129129
<div class="flex max-w-350 mx-auto">
130-
<div class="hidden lg:block w-64 shrink-0 border-r h-[calc(100vh-var(--header-height))] overflow-y-auto sticky top-(--header-height) py-6 pl-3 pr-3" transition:animate="none">
130+
<div class="hidden lg:block w-64 shrink-0 border-r h-[calc(100vh-var(--header-height))] overflow-y-auto sticky top-(--header-height) py-6 pl-3 pr-3" transition:persist transition:animate="none">
131131
<Sidebar items={navItems} currentPath={currentPath} client:load />
132132
</div>
133133
<main class="flex-1 min-w-0 px-4 sm:px-8 py-6" transition:animate="none">

0 commit comments

Comments
 (0)