alangrainger / obsidian-frontmatter-modified-date

Automatically update a frontmatter/YAML modified date field
MIT License
63 stars 10 forks source link

Conflict between typing event and front matter update ("Merging changes" popup) can cause data loss #32

Closed nuanjanP closed 2 days ago

nuanjanP commented 1 week ago

First, let me say thank you for this wonderful plugin. It helped me a lot these past months :)

Now to the topic. I encounter this popup on a regular basis, and usually I won't think too much, but today I realized there are cases where this conflict of typing and front matter updating can cause data loss. I imagine this issue maybe what @creativefibro has previously raised in issue #15.

Concretely, the text last inserted (in my case, 4 entire lines of text, because I was rapidly copying and pasting things) disappeared right after the popup appeared. And multiple undos (repeated Ctrl+Z's) do seem to confirm this by bringing back the text and rewinding the last modified time.

Personally I've already edited the timeout field in the jata.json file to 90 to try to avoid this, but I thought at least I should also report this phenomenon. Hope this helps.

alangrainger commented 2 days ago

Sadly it's just the way Obsidian handles the frontmatter updates, and missing text can sometimes be expected based on what I see in the Obsidian forums.

Frontmatter is updated using Obsidian's built-in processFrontMatter() method, so any bug in this method will need to be fixed upstream by the Obsidian team.

https://github.com/alangrainger/obsidian-frontmatter-modified-date/blob/568e7264a19839fa41c7cc23543f315b453b1669/src/main.ts#L93

There's nothing I can do at this end sorry, so I can only close this ticket.

alangrainger commented 2 days ago

@nuanjanP I have published a new release 1.4.4 which MAY have a slight improvement. Please test and see how it goes.

What I've done is move the modified date computations out of the frontmatter update block, so if there's any slight delay it won't cause the frontmatter update process to be running for too long. This has a tiny chance of improving things for you.

https://github.com/alangrainger/obsidian-frontmatter-modified-date/blob/2ddef525dfc8d29a71f40fb1defa1f0923c9ec70/src/main.ts#L140-L149