Skip to content

Commit 7454abd

Browse files
Copilothotlong
andcommitted
Fix: Make useSidebar hook gracefully handle missing provider during SSR
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 3796bd3 commit 7454abd

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

packages/components/src/ui/sidebar.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ const SidebarContext = React.createContext<SidebarContextProps | null>(null)
5555
function useSidebar() {
5656
const context = React.useContext(SidebarContext)
5757
if (!context) {
58-
throw new Error("useSidebar must be used within a SidebarProvider.")
58+
// Return default values when no provider exists (e.g., during SSR/prerendering)
59+
// This allows components to gracefully degrade without breaking the build
60+
return {
61+
state: "expanded" as const,
62+
open: true,
63+
setOpen: () => {},
64+
openMobile: false,
65+
setOpenMobile: () => {},
66+
isMobile: false,
67+
toggleSidebar: () => {},
68+
}
5969
}
6070

6171
return context

0 commit comments

Comments
 (0)