Skip to content

Commit 8b1dea8

Browse files
authored
Merge pull request #236 from objectstack-ai/copilot/fix-prerendering-error-header-bar
2 parents 73a236e + ebfd6a5 commit 8b1dea8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/components/src/ui/sidebar.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,22 @@ type SidebarContextProps = {
5252

5353
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
5454

55+
// Default sidebar state for when no provider exists (e.g., during SSR/prerendering)
56+
const DEFAULT_SIDEBAR_STATE: SidebarContextProps = {
57+
state: "expanded",
58+
open: true,
59+
setOpen: () => {},
60+
openMobile: false,
61+
setOpenMobile: () => {},
62+
isMobile: false,
63+
toggleSidebar: () => {},
64+
}
65+
5566
function useSidebar() {
5667
const context = React.useContext(SidebarContext)
5768
if (!context) {
58-
throw new Error("useSidebar must be used within a SidebarProvider.")
69+
// Return default values to allow components to gracefully degrade without breaking the build
70+
return DEFAULT_SIDEBAR_STATE
5971
}
6072

6173
return context

0 commit comments

Comments
 (0)