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:
@@ -312,6 +312,24 @@ describe('useNoteActions hook', () => {
|
||||
expect(createdContent).toContain('title: Test Note')
|
||||
})
|
||||
|
||||
it('handleCreateNote opens tab immediately (before addEntry resolves)', () => {
|
||||
const callOrder: string[] = []
|
||||
const trackedAddEntry = vi.fn(() => { callOrder.push('addEntry') })
|
||||
const config = makeConfig()
|
||||
config.addEntry = trackedAddEntry
|
||||
|
||||
const { result } = renderHook(() => useNoteActions(config))
|
||||
|
||||
act(() => {
|
||||
result.current.handleCreateNote('Fast Note', 'Note')
|
||||
})
|
||||
|
||||
// Tab should be open with the new note
|
||||
expect(result.current.tabs).toHaveLength(1)
|
||||
expect(result.current.tabs[0].entry.title).toBe('Fast Note')
|
||||
expect(result.current.activeTabPath).toContain('note/fast-note.md')
|
||||
})
|
||||
|
||||
it('handleCreateType creates type entry', () => {
|
||||
const { result } = renderHook(() => useNoteActions(makeConfig()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user