Skip to content

fix(studio): prevent SourceEditor recreation on every keystroke#786

Closed
Jefsky wants to merge 1 commit into
heygen-com:mainfrom
Jefsky:fix/source-editor-recreation
Closed

fix(studio): prevent SourceEditor recreation on every keystroke#786
Jefsky wants to merge 1 commit into
heygen-com:mainfrom
Jefsky:fix/source-editor-recreation

Conversation

@Jefsky
Copy link
Copy Markdown

@Jefsky Jefsky commented May 13, 2026

Summary

The SourceEditor component was destroying and recreating the CodeMirror EditorView on every keystroke, because mountEditor was used as both a callback ref and a useCallback with content in its dependency array.

What changed

  1. Removed content from the mountEditor dependency array
  2. Added a contentRef to pass initial content without subscribing to changes
  3. Added a useEffect that syncs external content changes (file switches, server refreshes) into the existing editor via dispatch() without recreating it

Result: cursor position, undo history, and focus are preserved across keystrokes.

Closes #624

@miguel-heygen
Copy link
Copy Markdown
Collaborator

Closing in favor of #624 which has the same fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants