From 2018bf4aa35bd642d2c20868c89bad30f1cb615f Mon Sep 17 00:00:00 2001 From: noteser-agent Date: Mon, 15 Jun 2026 08:19:39 +0300 Subject: [PATCH] perf(editor): stop blocking full-doc parse on note open The heading-fold foldService forced ensureSyntaxTree(doc.length, 5000ms) on every per-note editor remount, causing a ~1s stall on each note switch. Use the non-blocking syntaxTree(state) like the other live- preview extensions; the fold gutter only needs visible lines. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/components/editor/foldableHeadings.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/editor/foldableHeadings.ts b/src/components/editor/foldableHeadings.ts index d09342b..0aae47a 100644 --- a/src/components/editor/foldableHeadings.ts +++ b/src/components/editor/foldableHeadings.ts @@ -4,7 +4,6 @@ import { foldGutter, codeFolding, syntaxTree, - ensureSyntaxTree, } from '@codemirror/language' import type { EditorState } from '@codemirror/state' import type { Tree } from '@lezer/common' @@ -45,10 +44,11 @@ interface HeadingInfo { const headingCache = new WeakMap() function resolveTree(state: EditorState): Tree { - // Force a full parse so folding works for the whole document (and in headless - // test states with no view driving incremental parsing). Falls back to the - // partial tree if the parse times out on a very large doc. - return ensureSyntaxTree(state, state.doc.length, 5000) ?? syntaxTree(state) + // Use the non-blocking parsed tree (same as the other live-preview + // extensions). The fold gutter only queries visible lines, so a forced + // full-document parse on every per-note editor remount is unnecessary and + // caused a ~1s stall on each note switch. + return syntaxTree(state) } function collectHeadings(state: EditorState): HeadingInfo[] {