fix: prevent crash when opening notes

Move setActiveTabPath after tab content is loaded to prevent Editor's
useEffect from firing before the tab exists in the tabs array. Add
try/catch around editor.replaceBlocks for defensive error handling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lucaronin
2026-02-17 17:52:10 +01:00
parent 829cd2ad95
commit b239de3719
2 changed files with 24 additions and 16 deletions

View File

@@ -111,10 +111,7 @@ export function useNoteActions(
return
}
// Set active immediately for instant visual feedback
setActiveTabPath(entry.path)
// Load content async
// Load content async, then add tab and set active together
try {
const content = isTauri()
? await invoke<string>('get_note_content', { path: entry.path })
@@ -123,12 +120,14 @@ export function useNoteActions(
if (prev.some((t) => t.entry.path === entry.path)) return prev
return [...prev, { entry, content }]
})
setActiveTabPath(entry.path)
} catch (err) {
console.warn('Failed to load note content:', err)
setTabs((prev) => {
if (prev.some((t) => t.entry.path === entry.path)) return prev
return [...prev, { entry, content: '' }]
})
setActiveTabPath(entry.path)
}
}, [])