Skip to content

fix(settings): wait for complete multi-part settings before syncing canonical mdbase type (#2758) - #2759

Merged
callumalpass merged 2 commits into
mainfrom
fix/2758-settings-type-definition-race
Dec 2, 2026
Merged

callumalpass merged 2 commits into
mainfrom
fix/2758-settings-type-definition-race

Conversation

@callumalpass

Copy link
Copy Markdown
Owner

Fixes #2758

Cause

When Turn on type definitions (enableMdbaseSpec) was enabled, changing a multi-part portable setting triggered an immediate canonical type sync in MdbaseSpecService:

  1. Task identification (taskIdentificationMethod, taskPropertyName, taskPropertyValue, taskTag): Switching Identify tasks by from Tag to Property while taskPropertyName was still empty (or clearing taskPropertyName / taskTag mid-edit) caused @tasknotes/model's buildMatch() to fall back to tag matching (tags.contains: task). writeCanonicalTypeSnapshot() wrote that fallback to _mdbase/types/task.md and immediately read it back through applyCanonicalState(), overwriting plugin.settings.taskIdentificationMethod back to "tag" (or snapping taskTag back to "task"). When SettingsContext.write() finished flushing and refreshed the UI, the warning disappeared and the property inputs flipped back to disabled.
  2. Custom filename format (storeTitleInFilename, taskFilenameFormat, customFilenameTemplate): Selecting "custom" with an empty customFilenameTemplate (or clearing the template mid-edit) caused buildCanonicalMdbaseResources() to throw (A custom TaskNotes filename format requires a template.), clearing canonical sync state and reverting settings on the next edit.
  3. App settings and in-progress text edits: applyCanonicalTaskTypeToSettings() unconditionally ran applyAppSettingsToPluginSettings() even when neither sources.record nor sources.legacyBinding was passed, reverting useBodyTemplate / useOccurrenceBodyTemplate to false (when their template path was empty) and snapping a cleared archiveFolder back to its default whenever any portable setting synced. Re-applying written canonical types on self-write also stripped trailing spaces while typing multi-word values.

Changes

  • Added hasIncompletePortableSettings() in src/services/mdbaseCanonicalConfig.ts to detect incomplete multi-part portable settings (property identification without a property name, tag identification without a tag, or custom filename format without a template).
  • Updated MdbaseSpecService.syncSettingsToCanonicalTypeSnapshot() to defer writing canonical types (and avoid creating empty metadata folders or writing fallback/unusable task match rules) while portable settings are incomplete, syncing automatically once the required field is filled in.
  • Extracted buildCanonicalSupportResources() so support resource checks do not invoke buildCanonicalMdbaseResources() on incomplete local settings.
  • Stopped writeCanonicalTypeSnapshot() from overwriting in-memory plugin.settings on self-writes, and updated applyCanonicalTaskTypeToSettings() to only apply app settings when sources.record or sources.legacyBinding is present.
  • Added unit regression tests in tests/unit/issues/issue-2758-settings-type-definition-race.test.ts and an Obsidian E2E regression test in e2e/issues/issue-2758-settings-type-definition-race.spec.ts.
  • Added a release note entry in docs/releases/unreleased.md.

Verification

  • npx jest tests/unit/issues/issue-2758-settings-type-definition-race.test.ts (7/7 failed before the fix, 7/7 pass after)
  • npm run e2e -- e2e/issues/issue-2758-settings-type-definition-race.spec.ts (passed in isolated Obsidian 1.14.2)
  • npm run typecheck (passed)
  • npm run lint (passed)
  • npm run build & npm run check:bundle-size (passed)
  • npm run i18n:verify, npm run test:i18n-source, npm run test:translation-contracts, npm run test:language-packs, npm run conformance:test (all passed)
  • npm test -- --maxWorkers=2 (864/865 suites, 6,748 tests passed; 4 unrelated SafeMetadata filesystem timeout flakes in tests/unit/services/mdbaseMetadataSwap.test.ts under heavy local host load)

@callumalpass
callumalpass merged commit 85e3364 into main Dec 2, 2026
3 checks passed
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.

[Bug]: Settings race when "Turn on type definition" enabled

1 participant