fix: defer vault entries update via startTransition for instant tab creation (#90)

On a 9000+ entry vault, creating a new note (Cmd+N) was slow because
the entries state update triggered expensive re-computations in NoteList
(filter + sort), Sidebar (type counts), and Editor (wikilink suggestions)
— all blocking the tab from appearing.

Fix: wrap setEntries/setAllContent/trackNew in React's startTransition so
they run as low-priority updates. The tab creation (setTabs/setActiveTabPath)
remains high-priority and renders in <50ms. The entries update is deferred
to idle time without blocking the UI.

Also reorder createAndPersist to call openTab before addEntry, making the
intent explicit: tab appears first, vault index updates second.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Luca Rossi
2026-02-26 11:41:46 +01:00
committed by GitHub
parent 981784270a
commit 8fbaff792b
3 changed files with 40 additions and 18 deletions

View File

@@ -193,15 +193,19 @@ function persistOptimistic(path: string, content: string, onFail: (p: string) =>
persistNewNote(path, content).catch(() => onFail(path))
}
/** Optimistically add entry to UI, open tab, and persist to disk. */
/** Optimistically open tab, add entry to vault, and persist to disk.
* Tab creation (setTabs/setActiveTabPath) runs at normal priority so the
* tab appears instantly. addEntry uses startTransition internally so the
* expensive entries update (NoteList re-filter/sort on 9000+ entries) is
* deferred and doesn't block the tab from rendering. */
function createAndPersist(
resolved: { entry: VaultEntry; content: string },
addFn: (e: VaultEntry, c: string) => void,
openTab: (e: VaultEntry, c: string) => void,
onFail: (p: string) => void,
): void {
addEntryWithMock(resolved.entry, resolved.content, addFn)
openTab(resolved.entry, resolved.content)
addEntryWithMock(resolved.entry, resolved.content, addFn)
persistOptimistic(resolved.entry.path, resolved.content, onFail)
}