-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Description
Typing in the title field of the editor has noticeable lag/delay. Each keystroke feels slow and glitchy compared to typing in the body of the note.
Root Cause Analysis
Every keystroke in the title triggers a cascade of work across multiple registerUpdateListener callbacks:
- TitlePlugin (
src/components/editor/plugins/title-plugin.tsx) — callsgetTextContent()(tree traversal), theneditor.getElementByKey()(DOM lookup), then togglesis-placeholderclass, then invokesonTitleChangecallback - onTitleChange handler (
src/components/lexical-editor.tsx) — triggers a Zustand store update (updateDocumentInStore) which can cause sidebar/app re-renders, plus a debounced IPC save - BlockPlaceholderPlugin — fires its own update listener doing DOM queries and classList operations
- FloatingToolbarPlugin — recalculates selection state with DOM tree walks
- OnChangePlugin — serializes the entire editor state to JSON on every change (debounced at 600ms, but the serialization itself runs synchronously)
- SectionIndicatorPlugin — mutation listener walks mutations to check parent nodes
All of these fire independently on every single keystroke with no batching or coordination.
Potential Optimizations
- Debounce or throttle the title text extraction and
onTitleChangecallback - Batch DOM operations (classList toggles, getElementByKey) via
requestAnimationFrame - Consider a single centralized update listener instead of 4+ independent ones
- Avoid calling
getTextContent()on every update — use a dirty flag or mutation listener instead - Profile whether the Zustand store update from
updateDocumentInStorecauses unnecessary re-renders in the sidebar
Reproduction
- Open any note
- Click into the title
- Type quickly — noticeable lag/delay between keystrokes and characters appearing
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels