fix: guard against missing sidebarProjectGroupingOverrides in client settings#2099
Conversation
…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
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ApprovabilityVerdict: Approved Defensive bug fix adding null-safety guards (optional chaining, default settings fallback, schema validation) for missing You can customize Macroscope's approvability policy. Learn more. |
Summary
Fixes a runtime crash:
Persisted client settings created before #2055 omit
sidebarProjectGroupingOverrides. Reading that field as a raw object then crashed wheneverresolveProjectGroupingMode(or the Sidebar override dialog) tried to look up a project's override using the physical project key.The composite
<environmentId>:/pathshape in the error message is the physical project key fromderivePhysicalProjectKey, which V8 surfaces verbatim because the failing access isundefined[physicalKey].Changes
apps/web/src/hooks/useSettings.ts: hydration now merges persisted snapshots withDEFAULT_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:readClientSettingsdecodes the on-disk JSON throughClientSettingsSchema(Schema.decodeUnknownSync) sowithDecodingDefaultapplies for missing fields. Previously it was a raw cast, which is what allowed the missing-field shape to reach React.apps/web/src/logicalProject.tsandapps/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 typecheckbun lint(no new warnings)bun fmtsidebarProjectGroupingOverridesand 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
sidebarProjectGroupingOverridesby making settings hydration/decoding fill defaults instead of leavingundefinedholes.Desktop
readClientSettingsnow decodes the on-disk JSON viaClientSettingsSchema(returningnullon decode failure), web settings hydration merges persisted values overDEFAULT_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
sidebarProjectGroupingOverridesin client settingsresolveProjectGroupingMode(logicalProject.ts) and theSidebarProjectItem.openProjectGroupingDialogcallback (Sidebar.tsx) to avoid runtime errors whensidebarProjectGroupingOverridesis undefined.readClientSettingsin clientPersistence.ts now validates persisted data againstClientSettingsSchema, returningnullif validation fails instead of returning an arbitrary object.hydrateClientSettingsin useSettings.ts merges persisted settings withDEFAULT_CLIENT_SETTINGSso missing fields always have defaults.Macroscope summarized bf875c3.