perf: speed up Cmd+N note creation from ~150ms to ~16ms (#81)
* fix: speed up Cmd+N note creation from ~150ms to ~16ms Root cause: the editor focus used a fixed 150ms setTimeout after note creation, even when the BlockNote editor was already mounted. The optimistic UI (state updates, tab opening) was already synchronous, but the focus delay dominated perceived latency. Changes: - Editor focus now uses requestAnimationFrame when editor is mounted (~16ms on 60Hz), falling back to 80ms timeout for first-mount only - Rust save_note_content creates parent directories automatically, preventing optimistic-UI revert when creating notes in new folders - Added perf timing markers (console.debug) to measure creation→focus Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci: retrigger after disk space cleanup --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -183,6 +183,11 @@ function navigateWikilink(entries: VaultEntry[], target: string, selectNote: (e:
|
||||
else console.warn(`Navigation target not found: ${target}`)
|
||||
}
|
||||
|
||||
/** Dispatch focus-editor event with perf timing marker. */
|
||||
function signalFocusEditor(): void {
|
||||
window.dispatchEvent(new CustomEvent('laputa:focus-editor', { detail: { t0: performance.now() } }))
|
||||
}
|
||||
|
||||
/** Persist to disk; on failure, call the revert handler. */
|
||||
function persistOptimistic(path: string, content: string, onFail: (p: string) => void): void {
|
||||
persistNewNote(path, content).catch(() => onFail(path))
|
||||
@@ -275,7 +280,7 @@ export function useNoteActions(config: NoteActionsConfig) {
|
||||
const title = generateUntitledName(entries, noteType, pendingNamesRef.current)
|
||||
pendingNamesRef.current.add(title)
|
||||
handleCreateNote(title, noteType)
|
||||
window.dispatchEvent(new CustomEvent('laputa:focus-editor'))
|
||||
signalFocusEditor()
|
||||
setTimeout(() => pendingNamesRef.current.delete(title), 500)
|
||||
}, [entries, handleCreateNote])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user