Skip to content

ENG-1454: Base getter() task#828

Open
sid597 wants to merge 52 commits intomainfrom
migration-block-init-staging-branch
Open

ENG-1454: Base getter() task#828
sid597 wants to merge 52 commits intomainfrom
migration-block-init-staging-branch

Conversation

@sid597
Copy link
Copy Markdown
Collaborator

@sid597 sid597 commented Feb 25, 2026

#DO NOT MERGE - until all the other prs are


Open with Devin

@linear
Copy link
Copy Markdown

linear bot commented Feb 25, 2026

@supabase
Copy link
Copy Markdown

supabase bot commented Feb 25, 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
Copy Markdown
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 2 additional findings.

Open in Devin Review

Copy link
Copy Markdown
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 7 additional findings in Devin Review.

Open in Devin Review

Comment on lines 241 to +244
export const QuerySettingsSchema = z.object({
"Hide query metadata": z.boolean().default(false),
"Hide query metadata": z.boolean().default(true),
"Default page size": z.number().default(10),
"Query pages": z.array(z.string()).default([]),
"Query pages": z.array(z.string()).default(["discourse-graph/queries/*"]),
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot Mar 1, 2026

Choose a reason for hiding this comment

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

🟡 Changed QuerySettingsSchema defaults corrupt legacy-path fallbacks

The QuerySettingsSchema defaults were changed ("Hide query metadata" from falsetrue, "Query pages" from []["discourse-graph/queries/*"]). These new defaults propagate into DEFAULT_PERSONAL_SETTINGS (computed at module load via PersonalSettingsSchema.parse({}) at accessors.ts:165), which is then used as the fallback value in getLegacyPersonalSetting().

Root cause and impact

In getLegacyPersonalSetting (accessors.ts:212-251), when a mapped key is found, the fallback default is read from DEFAULT_PERSONAL_SETTINGS:

return getSetting<unknown>(
  mappedOldKey,
  readPathValue(DEFAULT_PERSONAL_SETTINGS, keys),
);

For keys = ["Query", "Hide query metadata"], this resolves to getSetting("hide-metadata", true). If the user has never explicitly set this value, getSetting returns true (the new default) instead of false (the old default). The intent of the legacy path is backward compatibility with the old system, but the fallback now returns different values than the old system provided.

Concretely:

  • Users who never explicitly set "Hide query metadata" will see query metadata hidden when it was previously shown.
  • Users who never explicitly set "Query pages" will get ["discourse-graph/queries/*"] instead of [].

The getters aren't called yet (being built in this PR), but when they are wired up, the legacy path will silently change behavior for users who haven't explicitly configured these settings.

Open in Devin Review

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

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
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 24 additional findings in Devin Review.

Open in Devin Review

Comment on lines +419 to +427
getGlobalSetting<boolean>([
"Suggestive mode",
"Include current page relations",
]) ?? false;
const shouldGrabParentChildContext =
(extensionAPI.settings.get(
"context-grab-parent-child-context",
) as boolean) ?? true;
getGlobalSetting<boolean>([
"Suggestive mode",
"Include parent and child blocks",
]) ?? false;
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot Mar 3, 2026

Choose a reason for hiding this comment

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

🔴 Hyde search defaults changed from true to false, degrading suggestive mode search quality

In hyde.ts, the old code read shouldGrabFromReferencedPages and shouldGrabParentChildContext from phantom extensionAPI keys (context-grab-from-referenced-pages, context-grab-parent-child-context) that were never written anywhere in the codebase. Since the keys never existed, extensionAPI.settings.get(...) always returned undefined, and the ?? true fallback ensured both flags were always true. The new code reads from the global accessor with a ?? false fallback. The schema defaults for "Include current page relations" and "Include parent and child blocks" are also false. This means for users who never explicitly configured these settings (which is everyone, since the UI writes to different keys), the behavior silently changes from always including referenced pages and parent/child blocks in the search to never including them. This degrades suggestive mode hyde search results.

Open in Devin Review

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

devin-ai-integration[bot]

This comment was marked as resolved.

sid597 added 11 commits March 3, 2026 18:26
* ENG-1454: Enable dual read feature flag

* add caller

* resolve merge conflicts

* review

* example fix

* review
* ENG-1455: Dual-read from old-system settings and from blockprops

* remove console.logs

* address review

* prettier

* add comment describing why we do it like this

* reviewed

* rebase, review

* address review

* explicit throw, now zodschema default reads

* replace throw with warn, throw was too strong, with warn we test if legacy and block props are same
…ult reads (#813)

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

* review, fix
* ENG-1473: Rebase onto updated eng-1472, resolve conflicts and fix missing import

* ENG-1473: Review fixes — remove dead extensionAPI params, fix type casts

* ENG-1473: Fix restrict-template-expressions warnings in query utils

* rename persistQueryPages → setQueryPages, setQueryPages → setInitialQueryPages

* restore legacy type coercion for query-pages
* ENG-1467: Port global setting consumer reads (→ getGlobalSetting)

* prettier

* rebase onto updated eng-1472, resolve conflicts and fix tsc
* ENG-1479: Port suggestive mode settings to dual-read

Add dual-read routing to getFeatureFlag for flags with legacy counterparts.
FEATURE_FLAG_LEGACY_MAP maps "Suggestive mode enabled" and "Enable left
sidebar" to their config tree reads, gated by isNewSettingsStoreEnabled().
Flags without legacy entries go straight to block props (no behavior change).

Migrate value reads from getFormattedConfigTree() / extensionAPI.settings
to accessors:

- index.ts: getUidAndBooleanSetting → getFeatureFlag (accessor handles
  legacy fallback now)
- AdminPanel: suggestiveModeEnabled.value → getFeatureFlag in both
  FeatureFlagsTab and main component. Removed unused useMemo.
- SuggestiveModeSettings: includePageRelations state init →
  getGlobalSetting. Dropped initialValue from both GlobalFlagPanels.
- hyde.ts: orphan extensionAPI.settings.get() reads →
  getGlobalSetting. Fixes bug where sync config toggles had no
  runtime effect (keys were never written by any code).

Structural UIDs remain with getFormattedConfigTree().
pageGroups.groups NOT migrated — type mismatch (legacy PageGroup has
UIDs, Zod PageGroup does not). Deferred to ENG-1470.

* Align hyde.ts fallback defaults with Zod schema

* Fix eslint naming-convention warnings in FEATURE_FLAG_LEGACY_MAP

* Add TODO(ENG-1484) for suggestive mode reactivity
* Rebase ENG-1468 onto eng-1472 (fresh redo)

* Remove unnecessary lazy initializer from complement useState

* Break circular dep: inline DISCOURSE_CONFIG_PAGE_TITLE

* Address review: case-insensitive attribute lookup, empty-string fallback, move DISCOURSE_CONFIG_PAGE_TITLE to data/constants
…er-based reactivity

- Extract mergeGlobalSectionWithAccessor/mergePersonalSectionsWithAccessor to
  getLeftSidebarSettings.ts (used by LeftSidebarView, GlobalSettings, PersonalSettings)
- Settings panels now actually use accessor values (not fire-and-forget)
- Replace setLeftSidebarFlagHandler with settingsEmitter pub/sub
- useConfig subscribes to emitter instead of old subscribe()
- Wire up global/personal/flag handlers in pullWatchers to emit
- Remove dead newValue===oldValue guard (hasPropChanged already checks)
- Remove dead ?./?? in personal merge (Zod defaults guarantee values)
toggleFoldedState mutates folded.uid in-place then dual-writes to
block props, triggering pull watch → emitter → buildConfig(). Without
refreshConfigTree(), buildConfig() reads stale UIDs from the cached
tree, overwriting the in-place mutation and orphaning Roam blocks.
@sid597 sid597 force-pushed the migration-block-init-staging-branch branch from 21b6000 to 3b4c80a Compare March 3, 2026 13:03
devin-ai-integration[bot]

This comment was marked as resolved.

sid597 added 21 commits March 9, 2026 16:33
…m settingKeys.ts

Replaces all raw string literals used as block-prop accessor paths in consumer files
with typed constants from settingKeys.ts. Adds TEMPLATE_SETTING_KEYS constant and
tightens KeyboardShortcutInput blockPropKey prop from string to keyof PersonalSettings.
…blockprop-key-pairs-to-shared-constant-or

ENG-1499: Convert legacy-blockprop key pairs to shared constant or typed key
…-of-getformattedconfigtree

ENG-1503: Replace getFormattedConfigTree consumers with direct helper calls
…props-migration

ENG-1519: Add legacy-to-blockprops migration, remove backedBy from schemea
…ettings-pages

ENG-735: Remove inline settings UI from config pages
devin-ai-integration[bot]

This comment was marked as resolved.

sid597 added 2 commits March 13, 2026 11:07
…nch' into eng-1484-reactive-settings-some-settings-require-reloading-the-graph

# Conflicts:
#	apps/roam/src/index.ts
#	apps/roam/src/utils/initializeObserversAndListeners.ts
…gs-some-settings-require-reloading-the-graph

ENG-1484: reactive settings for triggers and suggestive mode overlay
devin-ai-integration[bot]

This comment was marked as resolved.

sid597 added 3 commits March 16, 2026 10:43
Resolved 11 conflicts:
- Replaced getFeatureFlag("Reified relation triples") with getStoredRelationsEnabled()
  (main moved reified relations from FeatureFlags to PersonalSettings)
- Removed "Reified relation triples" from FeatureFlagsSchema, kept "Use new settings store"
- Kept toDiscourseNode + added migrateNodeBlockProps in accessors.ts (both needed)
- Dropped MigrationTab from AdminPanel (moved to HomePersonalSettings on main)
- Migrated DiscourseContextOverlay score validation to use accessors instead of
  legacy tree reads (getSubTree/getSettingValueFromTree/getBasicTreeByParentUid)
- Removed dead legacy imports (getSetting, AUTO_CANVAS_RELATIONS_KEY from Tldraw.tsx;
  USE_REIFIED_RELATIONS from accessors.ts)
- Zero net increase in legacy reader call sites
…ing-branch

Resolved 2 import conflicts in canvas files — keep both sides (accessor
imports + new canvas sync/posthog imports).
* ENG-1470: Fix dual-read gaps found during flag-ON validation

Bootstrap legacy config blocks in initSchema so the plugin works on
fresh graphs without createConfigObserver/configPageTabs:
- trigger, grammar/relations, export, Suggestive Mode, Left Sidebar
- Reuses existing ensureBlocksExist/buildBlockMap helpers + DEFAULT_RELATION_VALUES

Fix duplicate block accumulation bugs:
- Page Groups: getSubTree auto-create race (ensureLegacyConfigBlocks pre-creates)
- Folded: lookup-based delete via getBasicTreeByParentUid instead of stale uid
- scratch/enabled: switched getSubTree({ parentUid }) to tree-based reads
- Folded in convertToComplexSection: removed erroneous block creation

Fix dual-read comparison:
- Replace JSON.stringify with deepEqual (handles key order, undefined/empty/false)
- Deterministic async ordering: await legacy write → refreshConfigTree → blockProp write
  (BlockPropSettingPanels, LeftSidebarView toggleFoldedState, AdminPanel suggestive mode)
- Use getPersonalSettings() (raw read) in toggleFoldedState to avoid mid-write comparison

Fix storedRelations import path (renderNodeConfigPage → data/constants)

* Fix dual-read mismatches and ZodError on discourse node parse

* Fix dual-read mismatches: alias timing, key-image re-render, deepEqual null

* Fix prettier formatting

* ENG-1574: Add dual-read console logs to setting setters (#914)

* ENG-1574: Add dual-read console logs to setting setters

Log legacy and block prop values with match/mismatch status
when a setting is changed. Fix broken import in storedRelations.

* ENG-1574: Add init-time dual-read log and window.dgDualReadLog()

Log all legacy vs block prop settings on init. Remove setter
logging. Expose dgDualReadLog() on window for on-demand use.

* ENG-1574: Fix eslint naming-convention warnings in init.ts

* ENG-1574: Use deepEqual instead of JSON.stringify for comparison

JSON.stringify is key-order dependent, causing false mismatches
when legacy and block props return keys in different order.

* ENG-1574: Remove dead code, use deepEqual for comparison

* ENG-1574: Fix review feedback — try-catch, flag exclusion, type guard

* Eng 1616 add getconfigtree equivalent for block pros on init (#944)

* ENG-1616: Bulk-read settings + thread snapshot (with timing logs)

Cut plugin load from ~20925ms to ~1327ms (94%) on a real graph by collapsing
per-call settings accessors into a single bulk read at init and threading
that snapshot through the init chain + observer callbacks.

Key changes:
- accessors.ts: bulkReadSettings() runs ONE pull query against the settings
  page's direct children and returns { featureFlags, globalSettings,
  personalSettings } parsed via Zod. readPathValue exported.
- getDiscourseNodes / getDiscourseRelations / getAllRelations: optional
  snapshot param threaded through, no breaking changes to existing callers.
- initializeDiscourseNodes + refreshConfigTree (+ registerDiscourseDatalog-
  Translators, getDiscourseRelationLabels): accept and forward snapshot.
- index.ts: bulkReadSettings() at the top of init; snapshot threaded into
  initializeDiscourseNodes, refreshConfigTree, initObservers,
  installDiscourseFloatingMenu, setInitialQueryPages, and the 3 sync sites
  inside index.ts itself.
- initializeObserversAndListeners.ts: snapshot threaded into the sync-init
  body; pageTitleObserver + leftSidebarObserver callbacks call
  bulkReadSettings() per fire (fresh, not stale); nodeTagPopupButtonObserver
  uses per-sync-batch memoization via queueMicrotask; hashChangeListener
  and nodeCreationPopoverListener use bulkReadSettings() per fire.
- findDiscourseNode: snapshot param added; getDiscourseNodes() default-arg
  moved inside the cache-miss branch so cache hits don't waste the call.
- isQueryPage / isCanvasPage / QueryPagesPanel.getQueryPages: optional
  snapshot param.
- LeftSidebarView.buildConfig / useConfig / mountLeftSidebar: optional
  initialSnapshot threaded for the first render; emitter-driven updates
  keep using live reads for post-mount reactivity.
- DiscourseFloatingMenu.installDiscourseFloatingMenu: optional snapshot.
- posthog.initPostHog: removed redundant internal getPersonalSetting check
  (caller already guards from the snapshot).
- migrateLegacyToBlockProps.hasGraphMigrationMarker: accepts the existing
  blockMap and does an O(1) lookup instead of a getBlockUidByTextOnPage scan.

Includes per-phase timing console.logs across index.ts, refreshConfigTree,
init.ts, initSettingsPageBlocks, and initObservers. Committed as a
checkpoint so we can reference measurements later; will be removed in the
next commit.

* ENG-1616: Remove plugin-load timing logs

Removes the per-phase console.log instrumentation added in the previous
commit. All the [DG Plugin] / [DG Nav] logs and their `mark()` / `markPhase()`
helpers are gone. Code behavior unchanged.

Dropped in this commit:
- index.ts: mark() closure, load start/done logs, and all phase marks.
- initializeObserversAndListeners.ts: markPhase() closure, per-observer marks,
  pageTitleObserver fire log, hashChangeListener [DG Nav] logs.
- LeftSidebarView.tsx: openTarget [DG Nav] click/resolve logs.
- refreshConfigTree.ts: mark() closure and all phase marks.
- init.ts: mark() closures in initSchema and initSettingsPageBlocks.
- accessors.ts: bulkReadSettings internal timing log.
- index.ts: unused getPluginElapsedTime import.

Previous commit (343dc11) kept as a checkpoint for future drill-downs.

* ENG-1616: Address review — typed indexing, restore dgDualReadLog, optional snapshot

- index.ts: move initPluginTimer() back to its original position (after
  early-return checks) so timing isn't started for graphs that bail out.
- Replace readPathValue + `as T | undefined` casts with direct typed
  indexing on the Zod-derived snapshot types across:
    - index.ts (disallowDiagnostics, isStreamlineStylingEnabled)
    - initializeObserversAndListeners.ts (suggestiveModeOverlay,
      pagePreview, discourseContextOverlay, globalTrigger,
      personalTriggerCombo, customTrigger) — also drops dead `?? "\\"`
      and `?? "@"` fallbacks since Zod defaults already populate them.
    - isCanvasPage.ts (canvasPageFormat)
    - setQueryPages.ts + QueryPagesPanel.tsx (nested [Query][Query pages])
- setQueryPages.setInitialQueryPages: snapshot is now optional with a
  getPersonalSetting fallback, matching the pattern used elsewhere
  (getQueryPages, isCanvasPage, etc.).
- init.ts: restore logDualReadComparison + window.dgDualReadLog so the
  on-demand console helper is available again. NOT auto-called on init —
  invoke window.dgDualReadLog() manually to dump the comparison.

* ENG-1616: Log total plugin load time

Capture performance.now() at the top of runExtension and log the
elapsed milliseconds just before the unload handler is wired, so we
have a single broad measurement of plugin init cost on each load.

* ENG-1616: Tighten init-only leaves to required snapshot, AGENTS.md compliance

Make snapshot required at six init-only leaves where caller audit
showed every site already passed one: installDiscourseFloatingMenu,
initializeDiscourseNodes, setInitialQueryPages, isQueryPage,
isCurrentPageCanvas, isSidebarCanvas. No cascade — only at the leaves.

Drop dead fallback code that was reachable only via the optional path:
- setQueryPages: legacy string|Record coercion ladder (snapshot is Zod-typed string[])
- DiscourseFloatingMenu: getPersonalSetting<boolean> cast site
- DiscourseFloatingMenu: unused props parameter (no caller ever overrode default)
- initializeObserversAndListeners: !== false dead pattern (Zod boolean default)
- initializeObserversAndListeners: as IKeyCombo cast (schema is structurally compatible)

AGENTS.md compliance for >2-arg functions:
- mountLeftSidebar: object-destructured params, both call sites updated
- installDiscourseFloatingMenu: kept at 2 positional via dead-props removal

posthog: collapse doInitPostHog wrapper into initPostHog (caller-side gating).
accessors: revert speculative readPathValue export (no consumer).
LeftSidebarView/DiscourseFloatingMenu: eslint-disable react/no-deprecated on
ReactDOM.render rewritten lines, matching existing codebase convention.

* ENG-1616: Address review — rename snapshot vars, flag-gate bulkRead, move PostHog guards

- Rename settingsSnapshot/callbackSnapshot/snap/navSnapshot → settings
- bulkReadSettings now checks "Use new settings store" flag and falls
  back to legacy reads when off, matching individual getter behavior
- Move encryption/offline guards into initPostHog (diagnostics check
  stays at call site to avoid race with async setSetting in enablePostHog)

* Fix legacy bulk settings fallback

* ENG-1617: se existing 'getConfigTree equivalent functions' for specific setting groups (#946)

* ENG-1616: Bulk-read settings + thread snapshot (with timing logs)

Cut plugin load from ~20925ms to ~1327ms (94%) on a real graph by collapsing
per-call settings accessors into a single bulk read at init and threading
that snapshot through the init chain + observer callbacks.

Key changes:
- accessors.ts: bulkReadSettings() runs ONE pull query against the settings
  page's direct children and returns { featureFlags, globalSettings,
  personalSettings } parsed via Zod. readPathValue exported.
- getDiscourseNodes / getDiscourseRelations / getAllRelations: optional
  snapshot param threaded through, no breaking changes to existing callers.
- initializeDiscourseNodes + refreshConfigTree (+ registerDiscourseDatalog-
  Translators, getDiscourseRelationLabels): accept and forward snapshot.
- index.ts: bulkReadSettings() at the top of init; snapshot threaded into
  initializeDiscourseNodes, refreshConfigTree, initObservers,
  installDiscourseFloatingMenu, setInitialQueryPages, and the 3 sync sites
  inside index.ts itself.
- initializeObserversAndListeners.ts: snapshot threaded into the sync-init
  body; pageTitleObserver + leftSidebarObserver callbacks call
  bulkReadSettings() per fire (fresh, not stale); nodeTagPopupButtonObserver
  uses per-sync-batch memoization via queueMicrotask; hashChangeListener
  and nodeCreationPopoverListener use bulkReadSettings() per fire.
- findDiscourseNode: snapshot param added; getDiscourseNodes() default-arg
  moved inside the cache-miss branch so cache hits don't waste the call.
- isQueryPage / isCanvasPage / QueryPagesPanel.getQueryPages: optional
  snapshot param.
- LeftSidebarView.buildConfig / useConfig / mountLeftSidebar: optional
  initialSnapshot threaded for the first render; emitter-driven updates
  keep using live reads for post-mount reactivity.
- DiscourseFloatingMenu.installDiscourseFloatingMenu: optional snapshot.
- posthog.initPostHog: removed redundant internal getPersonalSetting check
  (caller already guards from the snapshot).
- migrateLegacyToBlockProps.hasGraphMigrationMarker: accepts the existing
  blockMap and does an O(1) lookup instead of a getBlockUidByTextOnPage scan.

Includes per-phase timing console.logs across index.ts, refreshConfigTree,
init.ts, initSettingsPageBlocks, and initObservers. Committed as a
checkpoint so we can reference measurements later; will be removed in the
next commit.

* ENG-1616: Remove plugin-load timing logs

Removes the per-phase console.log instrumentation added in the previous
commit. All the [DG Plugin] / [DG Nav] logs and their `mark()` / `markPhase()`
helpers are gone. Code behavior unchanged.

Dropped in this commit:
- index.ts: mark() closure, load start/done logs, and all phase marks.
- initializeObserversAndListeners.ts: markPhase() closure, per-observer marks,
  pageTitleObserver fire log, hashChangeListener [DG Nav] logs.
- LeftSidebarView.tsx: openTarget [DG Nav] click/resolve logs.
- refreshConfigTree.ts: mark() closure and all phase marks.
- init.ts: mark() closures in initSchema and initSettingsPageBlocks.
- accessors.ts: bulkReadSettings internal timing log.
- index.ts: unused getPluginElapsedTime import.

Previous commit (343dc11) kept as a checkpoint for future drill-downs.

* ENG-1616: Address review — typed indexing, restore dgDualReadLog, optional snapshot

- index.ts: move initPluginTimer() back to its original position (after
  early-return checks) so timing isn't started for graphs that bail out.
- Replace readPathValue + `as T | undefined` casts with direct typed
  indexing on the Zod-derived snapshot types across:
    - index.ts (disallowDiagnostics, isStreamlineStylingEnabled)
    - initializeObserversAndListeners.ts (suggestiveModeOverlay,
      pagePreview, discourseContextOverlay, globalTrigger,
      personalTriggerCombo, customTrigger) — also drops dead `?? "\\"`
      and `?? "@"` fallbacks since Zod defaults already populate them.
    - isCanvasPage.ts (canvasPageFormat)
    - setQueryPages.ts + QueryPagesPanel.tsx (nested [Query][Query pages])
- setQueryPages.setInitialQueryPages: snapshot is now optional with a
  getPersonalSetting fallback, matching the pattern used elsewhere
  (getQueryPages, isCanvasPage, etc.).
- init.ts: restore logDualReadComparison + window.dgDualReadLog so the
  on-demand console helper is available again. NOT auto-called on init —
  invoke window.dgDualReadLog() manually to dump the comparison.

* ENG-1616: Log total plugin load time

Capture performance.now() at the top of runExtension and log the
elapsed milliseconds just before the unload handler is wired, so we
have a single broad measurement of plugin init cost on each load.

* ENG-1616: Tighten init-only leaves to required snapshot, AGENTS.md compliance

Make snapshot required at six init-only leaves where caller audit
showed every site already passed one: installDiscourseFloatingMenu,
initializeDiscourseNodes, setInitialQueryPages, isQueryPage,
isCurrentPageCanvas, isSidebarCanvas. No cascade — only at the leaves.

Drop dead fallback code that was reachable only via the optional path:
- setQueryPages: legacy string|Record coercion ladder (snapshot is Zod-typed string[])
- DiscourseFloatingMenu: getPersonalSetting<boolean> cast site
- DiscourseFloatingMenu: unused props parameter (no caller ever overrode default)
- initializeObserversAndListeners: !== false dead pattern (Zod boolean default)
- initializeObserversAndListeners: as IKeyCombo cast (schema is structurally compatible)

AGENTS.md compliance for >2-arg functions:
- mountLeftSidebar: object-destructured params, both call sites updated
- installDiscourseFloatingMenu: kept at 2 positional via dead-props removal

posthog: collapse doInitPostHog wrapper into initPostHog (caller-side gating).
accessors: revert speculative readPathValue export (no consumer).
LeftSidebarView/DiscourseFloatingMenu: eslint-disable react/no-deprecated on
ReactDOM.render rewritten lines, matching existing codebase convention.

* ENG-1617: Single-pull settings reads + dialog snapshot threading

`getBlockPropBasedSettings` now does one Roam `pull` that returns the
settings page's children with their string + uid + props in one shot,
replacing the `q`-based `getBlockUidByTextOnPage` (~290ms per call) plus
a second `pull` for props. `setBlockPropBasedSettings` reuses the same
helper for the uid lookup so we have a single pull-and-walk pattern.

`SettingsDialog` captures a full settings snapshot once at mount via
`useState(() => bulkReadSettings())` and threads `featureFlags` and
`personalSettings` down to `HomePersonalSettings`. Each child component
(`PersonalFlagPanel`, `NodeMenuTriggerComponent`,
`NodeSearchMenuTriggerSetting`, `KeyboardShortcutInput`) accepts an
`initialValue` prop and seeds its local state from the snapshot instead
of calling `getPersonalSetting` on mount. `PersonalFlagPanel`'s
`initialValue` precedence flips so the prop wins when provided;
`QuerySettings` callers without a prop still hit the existing fallback.

`getDiscourseNodes`, `getDiscourseRelations`, and `getAllRelations`
narrow their snapshot parameter to `Pick<SettingsSnapshot, ...>` to
declare which fields each function actually reads.

Adds a one-line `console.log` in `SettingsDialog` reporting the dialog
open time, kept as an ongoing perf monitor.

* ENG-1617: Refresh snapshot on Home tab nav + reuse readPathValue

CodeRabbit catch: with `renderActiveTabPanelOnly={true}`, the Home tab's
panel unmounts/remounts when the user navigates away and back. Each
re-mount re-runs `useState(() => initialValue ?? false)` in
`BaseFlagPanel`, re-seeding from whatever `initialValue` is currently
passed. Because the dialog held the snapshot in a non-updating
`useState`, that path served stale values, so toggles made earlier in
the same dialog session would visually revert after a tab round-trip.

Fix: hold the snapshot in a stateful slot and refresh it via
`bulkReadSettings()` from the Tabs `onChange` handler when the user
navigates back to Home. The setState batches with `setActiveTabId`, so
the new mount sees the fresh snapshot in the same render.

Also replace the inline reducer in `getBlockPropBasedSettings` with the
existing `readPathValue` util — same traversal but consistent with the
rest of the file and adds array-index handling for free.

* ENG-1617: Per-tab snapshot threading via bulkReadSettings

Replaces the dialog-level snapshot from earlier commits with a per-tab
snapshot model that scales to every tab without per-tab plumbing in the
dialog itself.

In accessors.ts, the three plural getters (getFeatureFlags,
getGlobalSettings, getPersonalSettings) now delegate to the existing
bulkReadSettings, which does one Roam pull on the settings page and
parses all three schemas in a single pass. The slow q-based
getBlockPropBasedSettings is deleted (it was only used by the plural
getters and the set path); setBlockPropBasedSettings goes back to
calling getBlockUidByTextOnPage directly. Writes are infrequent enough
that the q cost is acceptable on the set path.

Each tab container that renders panels at mount captures one snapshot
via useState(() => bulkReadSettings()) and threads the relevant slice as
initialValue down to its panels: HomePersonalSettings, QuerySettings,
GeneralSettings, ExportSettings. The Personal and Global panels in
BlockPropSettingPanels.tsx flip their initialValue precedence to prefer
the prop and fall back to the live read only when the prop is missing,
so callers that don't pass initialValue (e.g. LeftSidebarGlobalSettings,
which already passes its own value) continue to behave the same way.

NodeMenuTriggerComponent, NodeSearchMenuTriggerSetting, and
KeyboardShortcutInput accept an initialValue prop and seed local state
from it instead of calling getPersonalSetting in their useState
initializer.

Settings.tsx wraps getDiscourseNodes() in useState so it doesn't re-run
on every dialog re-render.

The dialog-level snapshot, the snapshot-refresh-on-Home-tab-nav
workaround, and the Pick<SettingsSnapshot, ...> type narrowings are all
gone.

* ENG-1617: Lift settings snapshot to SettingsDialog, thread to all tabs

Move bulkReadSettings() from per-tab useState into a single call at
SettingsDialog mount. Each tab receives its snapshot slice (globalSettings,
personalSettings, featureFlags) as props. Remove dual-read mismatch
console.warn logic from accessors. Make initialValue caller-provided in
BlockPropSettingPanel wrappers. Add TabTiming wrapper for per-tab
commit/paint perf measurement.

* ENG-1617: Remove timing instrumentation, per-call dual-read, flag-aware bulkReadSettings

- Remove TabTiming component and all console.log timing from Settings dialog
- Remove per-call dual-read comparison from getGlobalSetting, getPersonalSetting,
  getDiscourseNodeSetting (keep logDualReadComparison for manual use)
- Make bulkReadSettings flag-aware: reads from legacy when flag is OFF,
  block props when ON
- Remove accessor fallbacks from Global/Personal wrapper panels (initialValue
  now always passed from snapshot)
- Remove getGlobalSetting/getPersonalSetting imports from BlockPropSettingPanels

* ENG-1617: Eliminate double bulkReadSettings calls in accessor functions

getGlobalSetting, getPersonalSetting, getFeatureFlag, getDiscourseNodeSetting
now each do a single bulkReadSettings() call instead of calling
isNewSettingsStoreEnabled() (which triggered a separate bulkReadSettings)
followed by another bulkReadSettings via the getter. bulkReadSettings already
handles the flag check and legacy/block-props routing internally.

* ENG-1617: Re-read snapshot on tab change to prevent stale initialValues

Replace useState with useMemo keyed on activeTabId so bulkReadSettings()
runs fresh each time the user switches tabs. Fixes stale snapshot when
renderActiveTabPanelOnly unmounts/remounts panels.

* ENG-1616: Address review — rename snapshot vars, flag-gate bulkRead, move PostHog guards

- Rename settingsSnapshot/callbackSnapshot/snap/navSnapshot → settings
- bulkReadSettings now checks "Use new settings store" flag and falls
  back to legacy reads when off, matching individual getter behavior
- Move encryption/offline guards into initPostHog (diagnostics check
  stays at call site to avoid race with async setSetting in enablePostHog)

* ENG-1617: Fix DiscourseNodeSelectPanel fallback to use first option instead of empty string

* ENG-1617: Rename snapshot variables to settings for clarity

* Fix legacy bulk settings fallback

* fix bug similar code
Copy link
Copy Markdown
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 52 additional findings in Devin Review.

Open in Devin Review

Comment on lines +13 to +29
export const PERSONAL_KEYS = {
discourseContextOverlay: "Discourse context overlay",
suggestiveModeOverlay: "Suggestive mode overlay",
textSelectionPopup: "Text selection popup",
disableSidebarOpen: "Disable sidebar open",
pagePreview: "Page preview",
hideFeedbackButton: "Hide feedback button",
autoCanvasRelations: "Auto canvas relations",
overlayInCanvas: "Overlay in canvas",
streamlineStyling: "Streamline styling",
disableProductDiagnostics: "Disable product diagnostics",
discourseToolShortcut: "Discourse tool shortcut",
personalNodeMenuTrigger: "Personal node menu trigger",
nodeSearchMenuTrigger: "Node search menu trigger",
leftSidebar: "Left sidebar",
query: "Query",
} as const satisfies Record<string, keyof PersonalSettings>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Missing legacy mapping for "Reified relation triples" causes migration to write incorrect default

The PERSONAL_KEYS constant in settingKeys.ts does not include an entry for "Reified relation triples", and PERSONAL_SCHEMA_PATH_TO_LEGACY_KEY in accessors.ts does not map it to its legacy extension setting key "use-reified-relations". Because readAllLegacyPersonalSettings() at accessors.ts:730-735 iterates only over Object.values(PERSONAL_KEYS), the "Reified relation triples" field is omitted from the legacy snapshot. When the migration in migrateLegacyToBlockProps.ts:291-296 runs PersonalSettingsSchema.safeParse(legacyPersonal), Zod fills in the schema default of false for this missing key and writes it to block props — even if the user had stored relations enabled via the "use-reified-relations" extension setting. This means when the "Use new settings store" feature flag is eventually enabled, personalSettings["Reified relation triples"] will read as false from block props, silently losing the user's preference. Runtime behavior is not currently affected because getStoredRelationsEnabled() in storedRelations.ts reads directly from extension settings, but the migrated data is wrong.

Prompt for agents
The PERSONAL_KEYS object in settingKeys.ts is missing an entry for the "Reified relation triples" personal setting. This causes readAllLegacyPersonalSettings() in accessors.ts to skip it when building the legacy snapshot, so the migration writes the Zod default (false) instead of reading the actual value from the extension setting key "use-reified-relations".

To fix:
1. Add a new entry to PERSONAL_KEYS in apps/roam/src/components/settings/utils/settingKeys.ts, e.g. reifiedRelationTriples: "Reified relation triples"
2. Add a mapping in PERSONAL_SCHEMA_PATH_TO_LEGACY_KEY in apps/roam/src/components/settings/utils/accessors.ts that maps pathKey([PERSONAL_KEYS.reifiedRelationTriples]) to "use-reified-relations"

This ensures the migration reads the correct stored value and writes it to block props.
Open in Devin Review

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

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