Skip to content

Commit b97def3

Browse files
committed
Fix shouldWrite skipping after reconciliation, warn on missing personal block
1 parent cd16a66 commit b97def3

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,12 @@ const shouldWrite = (
4848
return true;
4949
}
5050

51-
// safeParse because some schemas (DiscourseNodeSchema) have required fields
52-
// with no defaults, so parse({}) would throw.
53-
const defaultsResult = schema.safeParse({});
54-
if (!defaultsResult.success) {
55-
// Can't determine schema defaults (e.g. DiscourseNodeSchema).
56-
// Compare Zod-normalized parsed legacy against current props directly.
57-
// Both sides are normalized so the comparison is apples-to-apples.
58-
// Safe on retry: if prior run already wrote parsedLegacy, they'll match
59-
// → skip. If user edited via settings UI, dual-write keeps both sides in
60-
// sync → match → skip. The only write happens when legacy genuinely
61-
// differs from current (first migration or tree-only edit).
62-
return JSON.stringify(parsedLegacy) !== JSON.stringify(currentProps);
63-
}
64-
65-
const defaults = defaultsResult.data as Record<string, unknown>;
66-
const propsMatch = JSON.stringify(currentProps) === JSON.stringify(defaults);
67-
const legacyDiffers =
68-
JSON.stringify(parsedLegacy) !== JSON.stringify(defaults);
69-
70-
return propsMatch && legacyDiffers;
51+
// Compare Zod-normalized parsed legacy against current props directly.
52+
// Safe on retry: if prior run already wrote parsedLegacy, they'll match
53+
// → skip. If user edited via settings UI, dual-write keeps both sides in
54+
// sync → match → skip. The only write happens when legacy genuinely
55+
// differs from current (first migration or tree-only edit).
56+
return JSON.stringify(parsedLegacy) !== JSON.stringify(currentProps);
7157
};
7258

7359
const migrateSection = ({
@@ -241,7 +227,12 @@ export const migratePersonalSettings = async (
241227

242228
const personalKey = getPersonalSettingsKey();
243229
const personalUid = blockUids[personalKey];
244-
if (!personalUid) return;
230+
if (!personalUid) {
231+
console.warn(
232+
`${LOG_PREFIX} personal: block not found for key "${personalKey}", skipping`,
233+
);
234+
return;
235+
}
245236

246237
const legacyPersonal = readAllLegacyPersonalSettings();
247238
const ok = migrateSection({

0 commit comments

Comments
 (0)