How to use app.fileManager.processFrontMatter

I also have problems using this.
I have a Templater Js script where I replace some text formatting then based on these operations I want to add to the frontmatter.

// Check if code needs to be executed
if (codeExec) {
    app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
        frontmatter['danglinglink_sorted'] = true;
        });
// Had setTimeout method here before but had timing issues with it – frontmatter key was added, then many times disappeared soon after – but even after removing setTimeout, the issue recurs
// if (codeExec) {
    // setTimeout(() => {
        // app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
            // frontmatter['danglinglink_sorted'] = true;
        // });
    // }, 300);
}

Not sure if this method is superior or better in any way for current file:

const currentFile = app.workspace.getActiveFile();
// ...rest of script
await app.fileManager.processFrontMatter(currentFile, frontmatter => {
        frontmatter['danglinglink_commentedout'] = true;

As you can see, the formerly used setTimeout method I commented out to try out the script without it but I didn’t manage to solve the issue.

The issue being: Obsidian throws the confounding Merging changes automatically… pop-up, and in about 1-2 seconds, the newly added property disappears.

It doesn’t happen every single time so I reckon the sending of the message and the root of the issue is that Obsidian saves the file (as it does every 2 seconds) at the same time one is manipulating the frontmatter.

Current workaround: undo the Templater command (press CNTRL+Z once or twice) and try again so the property value sticks.

I am not sure the MetaEdit way of adding a property would be exempt of having the same effect. I suspect not.

EDIT:
See my recent revelations here.