Skip to content

waitForPendingLinkUpdates

Waits until Obsidian’s own in-flight link update has decided which links to rewrite.

FileManager.runAsyncLinkUpdate() snapshots every reference’s resolved paths, sets FileManager.inProgressUpdates to an array, and invokes the passed handler — the handler being what performs the actual rename. In its finally block it sets inProgressUpdates back to null and then immediately calls FileManager.updateAllLinks(), whose per-reference decision — rewrite only when the link’s resolved paths changed — runs synchronously, with no await in between. So observing a null inProgressUpdates proves that decision has already been made.

That matters for any code that temporarily registers a phantom file at a path that no longer exists (see registerFiles in metadata-cache.ts) and holds that registration across an await: while it is live, a link to the old path still resolves, so Obsidian concludes nothing changed and silently rewrites nothing. Awaiting this function before registering keeps the phantom out of that decision.

Import:

import { waitForPendingLinkUpdates } from 'obsidian-dev-utils/obsidian/file-manager';

Signature:

function waitForPendingLinkUpdates(app: App): Promise<void>

Parameters:

ParameterTypeDescription
appAppThe Obsidian app instance.

Returns: Promise<void> — A Promise that resolves once no link update is in flight.