Skip to content

fix: guard against missing sidebarProjectGroupingOverrides in client settings#2099

Merged
juliusmarminge merged 1 commit intopingdotgg:mainfrom
juliusmarminge:fix/sidebar-project-grouping-overrides-undefined
Apr 17, 2026
Merged

fix: guard against missing sidebarProjectGroupingOverrides in client settings#2099
juliusmarminge merged 1 commit intopingdotgg:mainfrom
juliusmarminge:fix/sidebar-project-grouping-overrides-undefined

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 17, 2026

Summary

Fixes a runtime crash:

TypeError: Cannot read properties of undefined (reading '<environmentId>:/path/to/project')

Persisted client settings created before #2055 omit sidebarProjectGroupingOverrides. Reading that field as a raw object then crashed whenever resolveProjectGroupingMode (or the Sidebar override dialog) tried to look up a project's override using the physical project key.

The composite <environmentId>:/path shape in the error message is the physical project key from derivePhysicalProjectKey, which V8 surfaces verbatim because the failing access is undefined[physicalKey].

Changes

  • apps/web/src/hooks/useSettings.ts: hydration now merges persisted snapshots with DEFAULT_CLIENT_SETTINGS, so any field added after a user last persisted their settings falls back to its default instead of leaving a hole in the snapshot.
  • apps/desktop/src/clientPersistence.ts: readClientSettings decodes the on-disk JSON through ClientSettingsSchema (Schema.decodeUnknownSync) so withDecodingDefault applies for missing fields. Previously it was a raw cast, which is what allowed the missing-field shape to reach React.
  • apps/web/src/logicalProject.ts and apps/web/src/components/Sidebar.tsx: defensive optional chaining at the two override lookup sites so a future regression of this kind degrades gracefully rather than throwing.

Test plan

  • bun typecheck
  • bun lint (no new warnings)
  • bun fmt
  • Manual: load app with a pre-existing client settings file that omits sidebarProjectGroupingOverrides and confirm the sidebar renders without throwing.

Made with Cursor


Note

Medium Risk
Touches client settings hydration/decoding and sidebar grouping override resolution; low complexity but could affect how persisted settings are interpreted across upgrades.

Overview
Prevents crashes when older persisted client settings are missing sidebarProjectGroupingOverrides by making settings hydration/decoding fill defaults instead of leaving undefined holes.

Desktop readClientSettings now decodes the on-disk JSON via ClientSettingsSchema (returning null on decode failure), web settings hydration merges persisted values over DEFAULT_CLIENT_SETTINGS, and the sidebar/grouping lookup sites use optional chaining so missing overrides degrade gracefully.

Reviewed by Cursor Bugbot for commit bf875c3. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Guard against missing sidebarProjectGroupingOverrides in client settings

  • Adds optional chaining in resolveProjectGroupingMode (logicalProject.ts) and the SidebarProjectItem.openProjectGroupingDialog callback (Sidebar.tsx) to avoid runtime errors when sidebarProjectGroupingOverrides is undefined.
  • readClientSettings in clientPersistence.ts now validates persisted data against ClientSettingsSchema, returning null if validation fails instead of returning an arbitrary object.
  • hydrateClientSettings in useSettings.ts merges persisted settings with DEFAULT_CLIENT_SETTINGS so missing fields always have defaults.
  • Behavioral Change: previously persisted client settings that fail schema validation will now be discarded and replaced with defaults on load.

Macroscope summarized bf875c3.

…settings

Persisted client settings created before the project-grouping feature was
added omit `sidebarProjectGroupingOverrides`. Reading that field as a raw
object then crashed with `TypeError: Cannot read properties of undefined
(reading '<environmentId>:/path')` whenever the sidebar resolved a
project's grouping mode.

- Merge persisted snapshots with `DEFAULT_CLIENT_SETTINGS` during web
  hydration so missing fields fall back to defaults.
- Decode desktop-persisted settings through `ClientSettingsSchema` so
  schema-level decoding defaults are applied (matches the browser path).
- Add defensive optional chaining at the two override lookup sites.

Made-with: Cursor
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 627ef914-c008-4a84-b7d3-cfbe8d325425

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Apr 17, 2026
@juliusmarminge juliusmarminge enabled auto-merge (squash) April 17, 2026 02:34
@juliusmarminge juliusmarminge merged commit 5490438 into pingdotgg:main Apr 17, 2026
12 checks passed
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 17, 2026

Approvability

Verdict: Approved

Defensive bug fix adding null-safety guards (optional chaining, default settings fallback, schema validation) for missing sidebarProjectGroupingOverrides in client settings. Changes are self-contained with clear intent and limited scope.

You can customize Macroscope's approvability policy. Learn more.

znoraka pushed a commit to znoraka/t3code that referenced this pull request Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant