Skip to content

Title typing is slow and laggy #77

@reddpy

Description

@reddpy

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:

  1. TitlePlugin (src/components/editor/plugins/title-plugin.tsx) — calls getTextContent() (tree traversal), then editor.getElementByKey() (DOM lookup), then toggles is-placeholder class, then invokes onTitleChange callback
  2. 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
  3. BlockPlaceholderPlugin — fires its own update listener doing DOM queries and classList operations
  4. FloatingToolbarPlugin — recalculates selection state with DOM tree walks
  5. OnChangePlugin — serializes the entire editor state to JSON on every change (debounced at 600ms, but the serialization itself runs synchronously)
  6. 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 onTitleChange callback
  • 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 updateDocumentInStore causes unnecessary re-renders in the sidebar

Reproduction

  1. Open any note
  2. Click into the title
  3. Type quickly — noticeable lag/delay between keystrokes and characters appearing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions