Repository navigation
Release 0.6.1: load settings before the settings tab asks for its rows - #22
Merged
Merged
Conversation
Obsidian 1.13 asks a settings tab for its definitions as soon as the tab is registered, so it can index the rows for settings search. onload() registered the tab without waiting for loadSettings(), so every row was built while this.settings was still the defaults — and since loadSettings() then replaced that object rather than filling it in, the rows kept reading and writing a copy nothing else could see. The tab showed the defaults for the rest of the session whatever data.json held, and an edit went into the orphaned copy while saveData() wrote the loaded one, so the change vanished. Register the tab once the load has settled, and update the settings object in place so a captured reference stays live. Fixes #21 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Patch release for the settings persistence fix (#21). The default actor stays okf-enforcer/0.6 — it tracks the minor version, as in 0.4.1. main.js is unchanged by the bump: nothing version-dependent compiles into it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Owner
Author
|
Added the 0.6.1 release bump to this PR rather than opening a separate
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21 — on Obsidian 1.13 the settings tab showed the defaults whatever
data.jsonheld, and edits made there were dropped.Root cause
Two things compounding, both in
main.ts:onload()registered the settings tab without waiting forloadSettings(). Obsidian 1.13 asks a tab forgetSettingDefinitions()the moment it is added, so it can index the rows for settings search. Every row was therefore built whilethis.settingswas still{ ...DEFAULT_SETTINGS }.loadSettings()assigned a fresh object (this.settings = { ...DEFAULT_SETTINGS }) instead of filling in the existing one.settingSpecs()opens withconst s = this.plugin.settings, so once the load swapped the object out, every row was reading and writing a copy nothing else could see.Hence the exact reported symptoms: the UI showed defaults regardless of
data.json, and an edit went into the orphaned copy whilesaveData()wrote the loaded one — so the change silently vanished.This is why only the UI was affected. Validation, exclusions and index generation read
this.settings.xafresh on each call, so they always followeddata.json, as the reporter observed.Fix
.catch(() => undefined).then(...), so a failed read still leaves a usable tab backed by defaults).Object.assign(this.settings, DEFAULT_SETTINGS)inloadSettings()— update in place, so a captured reference stays live.Either change alone would fix the reported case; both are here because each closes a separate hole. #2 in particular means the settings object no longer has an identity that anything can go stale against.
Verification
Throwaway esbuild harness with a fake Obsidian, run against
HEAD:main.tsand the working tree. It models 1.13's behaviour —getSettingDefinitions()called ataddSettingTab()— with adata.jsondeliberately unlike the defaults (defaultType: "note",excludeFolders: ["Templates","Archive","Inbox"],batchSize: 250) and an asyncloadData():tsc --noEmitis clean;main.jsrebuilt. The harness was scratch and is not in the diff.Notes
No migration needed — nothing was written to
data.jsonthat shouldn't have been; edits were dropped, not corrupted. A vault that hit this just needs to reopen Settings.Thanks to @antonym9535 for the report, and for tracing it into
main.js— the diagnosis there pointed straight at the registration ordering.🤖 Generated with Claude Code