Skip to content

Comments

ENG-1472: Refactor BlockPropSettingPanels to add accessor-backed default reads (with initialValue fallback)#813

Open
sid597 wants to merge 1 commit intoeng-1455-add-old-system-read-routing-to-accessor-gettersfrom
eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed
Open

ENG-1472: Refactor BlockPropSettingPanels to add accessor-backed default reads (with initialValue fallback)#813
sid597 wants to merge 1 commit intoeng-1455-add-old-system-read-routing-to-accessor-gettersfrom
eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed

Conversation

@sid597
Copy link
Collaborator

@sid597 sid597 commented Feb 22, 2026


Open with Devin

Summary by CodeRabbit

  • Refactor
    • Improved settings initialization mechanism with enhanced fallback support across global, personal, and feature flag setting panels. Changes ensure more robust setting retrieval while maintaining existing component behavior.

@linear
Copy link

linear bot commented Feb 22, 2026

@supabase
Copy link

supabase bot commented Feb 22, 2026

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

Copy link
Collaborator Author

sid597 commented Feb 22, 2026

@sid597
Copy link
Collaborator Author

sid597 commented Feb 22, 2026

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

✅ Actions performed

Full review triggered.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

This PR refactors BlockPropSettingPanels.tsx to introduce a readWithFallback helper and replaces direct initialValue usage with calls to setting accessor functions (getGlobalSetting, getPersonalSetting, getFeatureFlag, getDiscourseNodeSetting), each with a fallback to existing initialValues.

Changes

Cohort / File(s) Summary
BlockPropSettingPanels Refactoring
apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx
Introduces readWithFallback helper and updates Global, Personal, and DiscourseNode setting panels to resolve initial values via dedicated accessor functions with fallback support. Adds imports for getGlobalSetting, getPersonalSetting, getFeatureFlag, and getDiscourseNodeSetting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: refactoring BlockPropSettingPanels to integrate accessor-backed default reads with initialValue fallback, which directly aligns with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx (1)

473-483: Consider logging caught errors for debuggability.

The bare catch silently swallows all exceptions — including unexpected ones (e.g., TypeError from a bug in readPathValue). This is a reasonable resilience trade-off for UI code, but a console.warn would make misconfigured keys or accessor bugs much easier to diagnose.

Proposed fix
 const readWithFallback = <T,>(
   reader: () => T | undefined,
   fallback?: T,
 ): T | undefined => {
   try {
     const value = reader();
     return value ?? fallback;
-  } catch {
+  } catch (e) {
+    console.warn("[readWithFallback] accessor threw, using fallback:", e);
     return fallback;
   }
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx`
around lines 473 - 483, The readWithFallback function currently swallows all
exceptions silently; update it to catch the error into a variable and call
console.warn (or processLogger if available) with a concise message including
the error and context (e.g., "readWithFallback failed" and the thrown error)
before returning the fallback; keep existing behavior of returning fallback on
exceptions and preserve the reader/fallback signature so callers of
readWithFallback continue to work unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx`:
- Around line 473-483: The readWithFallback function currently swallows all
exceptions silently; update it to catch the error into a variable and call
console.warn (or processLogger if available) with a concise message including
the error and context (e.g., "readWithFallback failed" and the thrown error)
before returning the fallback; keep existing behavior of returning fallback on
exceptions and preserve the reader/fallback signature so callers of
readWithFallback continue to work unchanged.

@sid597 sid597 force-pushed the eng-1455-add-old-system-read-routing-to-accessor-getters branch from 5a02381 to b67fd5f Compare February 23, 2026 10:40
@sid597 sid597 force-pushed the eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed branch 2 times, most recently from c635833 to b1ace1a Compare February 23, 2026 13:51
@sid597 sid597 force-pushed the eng-1455-add-old-system-read-routing-to-accessor-getters branch 2 times, most recently from adf5fb5 to 75d22ad Compare February 23, 2026 14:13
@sid597 sid597 force-pushed the eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed branch 2 times, most recently from c90e2c8 to 3b1643c Compare February 23, 2026 14:31
@sid597 sid597 force-pushed the eng-1455-add-old-system-read-routing-to-accessor-getters branch from 75d22ad to cc8a3f2 Compare February 23, 2026 14:31
@sid597 sid597 force-pushed the eng-1455-add-old-system-read-routing-to-accessor-getters branch from cc8a3f2 to c7a64a1 Compare February 23, 2026 14:35
@sid597 sid597 force-pushed the eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed branch from 3b1643c to ee38a5f Compare February 23, 2026 14:35
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 10 additional findings in Devin Review.

Open in Devin Review

settingKeys={[featureKey as string]}
setter={featureFlagSetter}
initialValue={initialValue}
initialValue={readWithFallback(() => getFeatureFlag(featureKey), initialValue)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 readWithFallback never falls back for FeatureFlagPanel because getFeatureFlag always returns boolean

The FeatureFlagPanel component uses readWithFallback(() => getFeatureFlag(featureKey), initialValue) to compute the initial value. However, getFeatureFlag always returns a boolean (never undefined or null) because FeatureFlagsSchema has .default(false) for every field. Since readWithFallback uses value ?? fallback, and false ?? initialValue evaluates to false, the caller's initialValue fallback is effectively dead code under normal conditions.

Root cause and impact

getFeatureFlag at apps/roam/src/components/settings/utils/accessors.ts:668-671 calls getFeatureFlags() which parses block props with FeatureFlagsSchema.parse(blockProps || {}). The schema defines all flags with .default(false), so even when no block props exist, the parse returns { "Enable left sidebar": false, ... }.

In readWithFallback at line 494-495:

const value = reader(); // returns false (not undefined)
return value ?? fallback; // false ?? initialValue → false

This means the legacy initialValue passed by callers (e.g., settings.leftSidebarEnabled.value in GeneralSettings.tsx:46) is ignored. For users who had a feature flag enabled in the legacy system but whose block props were initialized with schema defaults (false), the checkbox will incorrectly show as unchecked.

For example, a user with the left sidebar enabled via the legacy block tree will see the checkbox unchecked after this change, because block props return false and the legacy initialValue={true} is never used as fallback.

Impact: Feature flag checkboxes may display incorrect initial state for existing users whose flags haven't been migrated to block props, contradicting the PR's stated goal of "with initialValue fallback."

Prompt for agents
In apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx, the readWithFallback function at line 489-499 uses the nullish coalescing operator (??), which only falls back for undefined/null. For getFeatureFlag, which always returns a boolean (false as default from schema), the fallback never triggers.

The fix depends on the desired semantics:

Option A: If the intent is to prefer block props when they have been explicitly set, and fall back to initialValue otherwise, then getFeatureFlag needs to distinguish between "explicitly set to false" and "defaulted to false because no value exists." This would require changing getFeatureFlag (or adding a variant) in apps/roam/src/components/settings/utils/accessors.ts around line 668-671 to return undefined when the block props don't contain an explicit value for the key, rather than returning the schema default.

Option B: If block props are always the source of truth for feature flags (because setFeatureFlag writes to block props), then the initialValue prop on FeatureFlagPanel is unnecessary and should be documented as such, or removed from the FeatureFlagPanel interface to avoid confusion.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@sid597 sid597 force-pushed the eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed branch from ee38a5f to c7c04c6 Compare February 23, 2026 15:28
@sid597 sid597 force-pushed the eng-1455-add-old-system-read-routing-to-accessor-getters branch 2 times, most recently from 0cf1a61 to d604e8d Compare February 23, 2026 15:31
@sid597 sid597 force-pushed the eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed branch from c7c04c6 to 2f2cf80 Compare February 23, 2026 15:31
@sid597 sid597 force-pushed the eng-1455-add-old-system-read-routing-to-accessor-getters branch from d604e8d to 5a6f356 Compare February 23, 2026 16:40
@sid597 sid597 force-pushed the eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed branch from 2f2cf80 to 080ebb1 Compare February 23, 2026 16:40
@sid597 sid597 force-pushed the eng-1472-refactor-blockpropsettingpanels-to-add-accessor-backed branch from 080ebb1 to f1855a5 Compare February 23, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant