perf: prevent FPS drops during navigation in FluxNoteView

- Narrow backlinks watcher from entire store to store.files only,
  reducing trigger count from ~8 to 2 per navigation
- Defer computation start by 300ms so it runs after the 250ms view
  transition animation completes
- Yield to the browser between each file iteration using
  scheduler.yield() (with setTimeout fallback) to avoid blocking frames

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Julien Calixte
2026-04-04 11:14:02 +02:00
parent d76182b2c2
commit 52d7c84bd0

View File

@@ -14,10 +14,19 @@ import { confirmMessage } from "@/utils/notif"
const isMarkdown = (filename?: string) => filename?.endsWith(".md") ?? false const isMarkdown = (filename?: string) => filename?.endsWith(".md") ?? false
const yieldToMain = () =>
"scheduler" in globalThis
? (globalThis as unknown as { scheduler: { yield: () => Promise<void> } }).scheduler.yield()
: new Promise<void>((r) => setTimeout(r, 0))
export const useComputeBacklinks = () => { export const useComputeBacklinks = () => {
const store = useUserRepoStore() const store = useUserRepoStore()
watch(store, async () => { watch(
() => store.files,
async () => {
await new Promise<void>((r) => setTimeout(r, 300))
if (!store.userSettings?.backlink) { if (!store.userSettings?.backlink) {
return return
} }
@@ -27,6 +36,8 @@ export const useComputeBacklinks = () => {
const backlinks: Map<string, Backlink[]> = new Map() const backlinks: Map<string, Backlink[]> = new Map()
for (const file of store.files) { for (const file of store.files) {
await yieldToMain()
if (!isMarkdown(file.path) || !file.sha) { if (!isMarkdown(file.path) || !file.sha) {
continue continue
} }
@@ -102,5 +113,6 @@ export const useComputeBacklinks = () => {
await data.update(backlinkNote) await data.update(backlinkNote)
backlinkEventBus.emit({ fileSha: sha }) backlinkEventBus.emit({ fileSha: sha })
} }
}) }
)
} }