Skip to content

Commit 94cf1e2

Browse files
committed
Fix dual-read mismatches and ZodError on discourse node parse
1 parent f561e23 commit 94cf1e2

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

apps/roam/src/components/settings/AdminPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ const FeatureFlagsTab = (): React.ReactElement => {
277277
}, []);
278278

279279
const [suggestiveModeEnabled, setSuggestiveModeEnabled] = useState(
280-
getFeatureFlag("Suggestive mode enabled"),
280+
() => getFeatureFlag("Suggestive mode enabled"),
281281
);
282282
const [suggestiveModeUid, setSuggestiveModeUid] = useState(
283283
legacySuggestiveModeMeta.suggestiveModeEnabledUid,

apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ const BaseFlagPanel = ({
232232
await syncFlagToBlock(checked);
233233
refreshConfigTree();
234234
setter(settingKeys, checked);
235-
onChange?.(checked);
235+
// Delay onChange to let the async Roam block.update flush before
236+
// the re-render reads block props via dual-read comparison.
237+
// TODO(ENG-1471): remove with dual-read cleanup
238+
setTimeout(() => onChange?.(checked), 100);
236239
};
237240

238241
return (

apps/roam/src/components/settings/utils/accessors.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ const getLegacyDiscourseNodeSetting = (
568568
enabled: specificationUid
569569
? getBasicTreeByParentUid(specificationUid).some(
570570
(c) => c.text === "enabled",
571-
) || specificationQuery.conditions.length > 0
571+
)
572572
: false,
573573
query: specificationQuery,
574574
},
@@ -936,11 +936,13 @@ export const setPersonalSetting = (keys: string[], value: json): void => {
936936
});
937937
};
938938

939-
const getRawDiscourseNodeBlockProps = (nodeType: string): json | undefined => {
939+
const getRawDiscourseNodeBlockProps = (
940+
nodeType: string,
941+
): Record<string, json> | undefined => {
940942
let pageUid = nodeType;
941943
let blockProps = getBlockPropsByUid(pageUid, []);
942944

943-
if (!blockProps || Object.keys(blockProps).length === 0) {
945+
if (!isRecord(blockProps) || Object.keys(blockProps).length === 0) {
944946
const lookedUpUid = getPageUidByPageTitle(
945947
`${DISCOURSE_NODE_PAGE_PREFIX}${nodeType}`,
946948
);
@@ -950,7 +952,9 @@ const getRawDiscourseNodeBlockProps = (nodeType: string): json | undefined => {
950952
}
951953
}
952954

953-
return blockProps;
955+
return isRecord(blockProps) && Object.keys(blockProps).length > 0
956+
? (blockProps as Record<string, json>)
957+
: undefined;
954958
};
955959

956960
export const getDiscourseNodeSettings = (

0 commit comments

Comments
 (0)