Skip to content

Commit c04cae3

Browse files
Fix stale sidebar open state when using prefetch links
When using Inertia prefetch links, the sidebar open state for that page is cached for 30 seconds (default) when hovering over a link. This can lead to unexpected behavior of the sidebar reopening or reclosing when navigating to the cached page. The router cache should be cleared whenever the sidebar state changes to clear out a potential stale sidebar open state. Reproduction: 1. Your app has 2 pages: Dashboard and Page 2. The prefetch attribute should be on both Inertia links in the sidebar. 2. Navigate to Page 2 with sidebar open. 3. Hover over (but don't click) the Dashboard link to prefetch it and then close the sidebar. 4. Now click on the Dashboard link to navigate to the cached page. The sidebar will now be open because that was the state the sidebar was in when prefetched. The Vue starter kit is not using prefetch links so it doesn't have this problem. If it is updated to use prefetch links, this fix will need added to it as well.
1 parent a112a23 commit c04cae3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

resources/js/components/app-sidebar-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function AppSidebarHeader({ breadcrumbs = [] }: { breadcrumbs?: Breadcrum
66
return (
77
<header className="border-sidebar-border/50 flex h-16 shrink-0 items-center gap-2 border-b px-6 transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12 md:px-4">
88
<div className="flex items-center gap-2">
9-
<SidebarTrigger className="-ml-1" />
9+
<SidebarTrigger className="-ml-1" onClick={()=>router.flushAll()} />
1010
<Breadcrumbs breadcrumbs={breadcrumbs} />
1111
</div>
1212
</header>

0 commit comments

Comments
 (0)