Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…bility Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a Next.js build failure during static site generation where the header-bar component's SidebarTrigger calls useSidebar() without a SidebarProvider in the tree, causing a hard error. The solution modifies useSidebar() to return safe default values instead of throwing when the provider is missing.
Changes:
- Modified
useSidebar()hook to returnDEFAULT_SIDEBAR_STATEwhen no provider exists, enabling graceful degradation during SSR/prerendering - Extracted
DEFAULT_SIDEBAR_STATEconstant with no-op functions for all sidebar operations
Comments suppressed due to low confidence (2)
packages/components/src/ui/sidebar.tsx:74
- Silently returning default values when the provider is missing hides configuration errors from developers. This approach differs from the established pattern in the codebase where other context hooks (useCarousel, useChart, useFormField, useSchemaContext) throw errors when used outside their providers.
Consider adding a development-time warning to help developers identify misconfigurations:
function useSidebar() {
const context = React.useContext(SidebarContext)
if (!context) {
if (process.env.NODE_ENV !== 'production') {
console.warn(
'useSidebar: No SidebarProvider found. Using default values. ' +
'This may indicate a missing SidebarProvider in your component tree.'
)
}
return DEFAULT_SIDEBAR_STATE
}
return context
}This preserves SSR compatibility while alerting developers during development that they may be missing proper setup.
function useSidebar() {
const context = React.useContext(SidebarContext)
if (!context) {
// Return default values to allow components to gracefully degrade without breaking the build
return DEFAULT_SIDEBAR_STATE
}
return context
}
packages/components/src/ui/sidebar.tsx:74
- The approach taken here differs from the ToggleGroupContext pattern (lines 16-21 in toggle-group.tsx) which provides a default value directly in createContext, preventing null checks altogether. Consider applying the same pattern here:
const SidebarContext = React.createContext<SidebarContextProps>(DEFAULT_SIDEBAR_STATE)Then simplify useSidebar to:
function useSidebar() {
return React.useContext(SidebarContext)
}This approach:
- Eliminates the null check entirely
- Aligns with the ToggleGroupContext implementation pattern
- Still provides SSR compatibility
- Maintains graceful degradation
Note: You'd still want to add a dev warning (see other comment) to help developers identify when they're missing the provider.
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
// Default sidebar state for when no provider exists (e.g., during SSR/prerendering)
const DEFAULT_SIDEBAR_STATE: SidebarContextProps = {
state: "expanded",
open: true,
setOpen: () => {},
openMobile: false,
setOpenMobile: () => {},
isMobile: false,
toggleSidebar: () => {},
}
function useSidebar() {
const context = React.useContext(SidebarContext)
if (!context) {
// Return default values to allow components to gracefully degrade without breaking the build
return DEFAULT_SIDEBAR_STATE
}
return context
}
| function useSidebar() { | ||
| const context = React.useContext(SidebarContext) | ||
| if (!context) { | ||
| throw new Error("useSidebar must be used within a SidebarProvider.") | ||
| // Return default values to allow components to gracefully degrade without breaking the build | ||
| return DEFAULT_SIDEBAR_STATE |
There was a problem hiding this comment.
The header-bar component (packages/components/src/renderers/navigation/header-bar.tsx:26) unconditionally renders a SidebarTrigger, but this creates an implicit coupling between header-bar and SidebarProvider. During SSR or when header-bar is used without a sidebar, the trigger renders but has no sidebar to control.
Consider one of these architectural improvements:
- Make the sidebar trigger optional in header-bar schema:
interface HeaderBarSchema {
showSidebarTrigger?: boolean; // Default: false for better SSR compatibility
// ... other props
}- Add a dedicated slot for the trigger so users explicitly choose when to include it:
interface HeaderBarSchema {
leftSlot?: SchemaNode[]; // Users can explicitly add SidebarTrigger here
// ... other props
}This would align with ObjectUI's principle of "JSON-driven composition" where components are explicitly configured rather than having implicit dependencies.
|
|
||
| const SidebarContext = React.createContext<SidebarContextProps | null>(null) | ||
|
|
||
| // Default sidebar state for when no provider exists (e.g., during SSR/prerendering) |
There was a problem hiding this comment.
The comment mentions "SSR/prerendering" but the actual issue is specifically about static site generation where components are rendered outside of a provider tree. Consider updating the comment to be more precise:
// Default sidebar state for graceful degradation when used outside SidebarProvider
// (e.g., during SSR, static generation, or standalone component usage)This clarifies that it's not just an SSR concern but a broader architectural pattern for components that may be rendered in isolation.
| // Default sidebar state for when no provider exists (e.g., during SSR/prerendering) | |
| // Default sidebar state for graceful degradation when used outside SidebarProvider | |
| // (e.g., during SSR, static generation, or standalone component usage) |
…jectui#8126)
`stale.yml` pinned `actions/stale@e00e804f6792d3fedb5bd3a27df2761c5f86c981`.
That SHA is not v9.0.0's commit and is not any commit in `actions/stale`, so
every run died in `Set up job` before the action started:
##[error]Unable to resolve action `actions/stale@e00e804f6792d3fedb5bd3a27df2761c5f86c981`,
unable to find version `e00e804f6792d3fedb5bd3a27df2761c5f86c981`
read verbatim from run 34172858995. Re-derived 2026-09-08: 236 completed
`schedule` runs, run #1 (21052154491, 2026-01-16T01:14:37Z) and run #236 both
`failure`. The comment beside the ref was right; only the SHA was wrong.
The replacement is measured, not looked up. A probe branch resolved the tag on
a real runner and the runner printed the mapping:
Download action repository 'actions/stale@v9.0.0' (SHA:28ca1036281a5e5922ead5184a1bbf96e5fc984e)
Ten candidate refs were probed in one run (34173534757): `actions/checkout@v7`
green as the positive control, the pinned SHA red as the negative control,
`main` / `master` / v8 / v9 / v9.0.0 / v10 / v11 all resolving, v12 not. v9.0.0
is kept because it is the version this file already declares; a bump is a
separate decision.
Then measured what turning it on does, before turning it on. This file with
only the SHA changed, plus `debug-only: true` and a read-only token, ran GREEN
(34173608021) -- the first success in this workflow's life -- and swept the
open board to exhaustion: 466 items (457 issues, 9 PRs) and a `Statistics:`
block with no stale, label or comment counter at all. Nothing marked, nothing
closed. Control on the same file the same day (34173673214), thresholds
dropped to 0: `New stale items: 125`, `Added items labels: 125`, `Added items
comments: 125`. The zero is a reading, not a silent instrument. It is zero
because the board is young -- oldest last-touch among 457 open issues is #5157
at 2026-08-21T08:18:51Z, 18 days against a 60-day threshold.
One line of behaviour changes: the SHA. Policy, permissions, cron and the
objectui#7956 accept-360 comment block are untouched.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FhBNJcLRZLe8M87VcUgpKr
Next.js build fails when prerendering pages containing
header-barcomponent. TheSidebarTriggercallsuseSidebar()which throws when noSidebarProviderexists in the context tree.Changes
useSidebar()to return safe defaults instead of throwing when provider is missingDEFAULT_SIDEBAR_STATEconstant for consistencyImplementation
This allows components using sidebar hooks to render during static generation while maintaining full functionality when wrapped in a provider.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
fonts.googleapis.com/usr/local/bin/node node /home/REDACTED/work/objectui/objectui/apps/site/node_modules/.bin/../next/dist/bin/next build(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.