fix(desktop): bypass Chromium editing pipeline for large paste & select-delete - #45812
Merged
Conversation
Contributor
🔎 Lint report:
|
OutThisLife
force-pushed
the
bb/composer-large-paste-lag
branch
from
June 13, 2026 20:44
91a1885 to
d040972
Compare
…ct-delete Large paste and Ctrl+A → Delete froze the composer for seconds — both routed through Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM). - insertPlainTextAtCaret: Range + text/<br> fragment (paste path) - deleteSelectionInEditor: range.deleteContents for non-collapsed Backspace/Delete - Shared composerSelectionRange helper; both flush via flushEditorToDraft Profiled live (47 KB / 122 paragraphs): paste 4474 ms → 13 ms; select-delete 1304 ms → 4 ms. Collapsed-caret deletes still native.
OutThisLife
force-pushed
the
bb/composer-large-paste-lag
branch
from
June 13, 2026 20:44
d040972 to
1801559
Compare
OutThisLife
enabled auto-merge (squash)
June 13, 2026 20:45
AIalliAI
pushed a commit
to AIalliAI/Hermes
that referenced
this pull request
Jun 14, 2026
…ct-delete (NousResearch#45812) Large paste and Ctrl+A → Delete froze the composer for seconds — both routed through Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM). - insertPlainTextAtCaret: Range + text/<br> fragment (paste path) - deleteSelectionInEditor: range.deleteContents for non-collapsed Backspace/Delete - Shared composerSelectionRange helper; both flush via flushEditorToDraft Profiled live (47 KB / 122 paragraphs): paste 4474 ms → 13 ms; select-delete 1304 ms → 4 ms. Collapsed-caret deletes still native.
T02200059
pushed a commit
to T02200059/hermes-agent
that referenced
this pull request
Jun 18, 2026
…ct-delete (NousResearch#45812) Large paste and Ctrl+A → Delete froze the composer for seconds — both routed through Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM). - insertPlainTextAtCaret: Range + text/<br> fragment (paste path) - deleteSelectionInEditor: range.deleteContents for non-collapsed Backspace/Delete - Shared composerSelectionRange helper; both flush via flushEditorToDraft Profiled live (47 KB / 122 paragraphs): paste 4474 ms → 13 ms; select-delete 1304 ms → 4 ms. Collapsed-caret deletes still native.
This was referenced Jun 20, 2026
[Bug]: Cmd/Ctrl+Z skips paste in desktop composer — pastes have no contentEditable undo entry
#49745
Closed
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
…ct-delete (NousResearch#45812) Large paste and Ctrl+A → Delete froze the composer for seconds — both routed through Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM). - insertPlainTextAtCaret: Range + text/<br> fragment (paste path) - deleteSelectionInEditor: range.deleteContents for non-collapsed Backspace/Delete - Shared composerSelectionRange helper; both flush via flushEditorToDraft Profiled live (47 KB / 122 paragraphs): paste 4474 ms → 13 ms; select-delete 1304 ms → 4 ms. Collapsed-caret deletes still native.
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
…ct-delete (NousResearch#45812) Large paste and Ctrl+A → Delete froze the composer for seconds — both routed through Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM). - insertPlainTextAtCaret: Range + text/<br> fragment (paste path) - deleteSelectionInEditor: range.deleteContents for non-collapsed Backspace/Delete - Shared composerSelectionRange helper; both flush via flushEditorToDraft Profiled live (47 KB / 122 paragraphs): paste 4474 ms → 13 ms; select-delete 1304 ms → 4 ms. Collapsed-caret deletes still native.
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…ct-delete (NousResearch#45812) Large paste and Ctrl+A → Delete froze the composer for seconds — both routed through Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM). - insertPlainTextAtCaret: Range + text/<br> fragment (paste path) - deleteSelectionInEditor: range.deleteContents for non-collapsed Backspace/Delete - Shared composerSelectionRange helper; both flush via flushEditorToDraft Profiled live (47 KB / 122 paragraphs): paste 4474 ms → 13 ms; select-delete 1304 ms → 4 ms. Collapsed-caret deletes still native.
This was referenced Jul 14, 2026
DavidMetcalfe
pushed a commit
to DavidMetcalfe/hermes-agent
that referenced
this pull request
Jul 15, 2026
After typing into the composer and pasting (Cmd+V), pressing Cmd+Z
unwound the typed characters instead of the paste — the paste had
no entry in the contentEditable undo stack.
Root cause: `handlePaste` (`app/chat/composer/index.tsx:625`) called
`event.preventDefault()` then mutated the DOM via `insertPlainTextAtCaret`
(`app/chat/composer/rich-editor.ts:150`), which uses `range.insertNode`
directly. Chromium's contentEditable undo manager only records changes
that flow through Blink's editing pipeline (`Editor::InsertText` et al.) —
i.e. native keystrokes, native paste, and `document.execCommand('insertText')`.
Direct DOM mutation bypasses that pipeline entirely, so no undo entry
was pushed for the paste and Cmd+Z stepped back through the keystrokes
typed before it.
Why the custom path existed: PR NousResearch#45812 replaced `execCommand('insertText')`
because the editing pipeline is ~O(n²) on multiline blobs (profiled
4474 ms on a 47 KB / 122-paragraph paste vs 13 ms through the bypass).
We keep that win for pathological pastes and only restore the slow
path for typical sizes.
Fix: new `pastePlainTextIntoEditor` helper in `rich-editor.ts` branches
on `text.length <= LARGE_PASTE_THRESHOLD_CHARS` (4096) and on the editor
being focused. Small focused pastes go through `execCommand('insertText')`,
which restores the undo entry. Everything else falls back to
`insertPlainTextAtCaret` exactly as before.
Tests: three new cases in `rich-editor.test.ts` covering the focused /
unfocused / oversized branches by stubbing `document.execCommand` (jsdom
doesn't define it natively).
TypeScript + ESLint clean. All 32 composer-area tests pass; full
vitest run shows no new failures (3 added passing tests; the 6
pre-existing failures are unrelated to this change).
DavidMetcalfe
added a commit
to DavidMetcalfe/hermes-agent
that referenced
this pull request
Jul 15, 2026
Route small pastes through document.execCommand('insertText') so
Chromium records an undo entry — Cmd+Z then reverts the paste instead
of skipping over it. Large pastes (>4096 chars) fall back to the
direct DOM-mutation path to avoid the O(n²) freeze (PR NousResearch#45812).
Also fixes two edge cases caught by cross-vendor review:
- Focus check relaxed to editor.contains(document.activeElement) so
pastes work when a chip/descendant has focus.
- execCommand failure handled: fall back to insertPlainTextAtCaret
on false return or exception.
Tests: pastePlainTextIntoEditor (5 tests: focused, unfocused, large,
descendant focus, execCommand failure fallback).
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…ct-delete (NousResearch#45812) Large paste and Ctrl+A → Delete froze the composer for seconds — both routed through Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM). - insertPlainTextAtCaret: Range + text/<br> fragment (paste path) - deleteSelectionInEditor: range.deleteContents for non-collapsed Backspace/Delete - Shared composerSelectionRange helper; both flush via flushEditorToDraft Profiled live (47 KB / 122 paragraphs): paste 4474 ms → 13 ms; select-delete 1304 ms → 4 ms. Collapsed-caret deletes still native.
6 tasks
OutThisLife
added a commit
that referenced
this pull request
Jul 26, 2026
The rich editor mutates its DOM through `Range` rather than the browser's
editing commands, because `execCommand('insertText')` is ~O(n²) on large
multiline blobs and froze the composer for seconds on a big paste (#45812).
Those mutations never reach Chromium's undo stack, so a paste was invisible to
it — Cmd+Z skipped straight past the pasted text and undid whatever edit came
before it, leaving the paste stranded and the earlier edit destroyed.
Owning the stack outright is the only coherent fix; a half-owned one interleaves
our snapshots with Chromium's own typing entries and undoes them out of order.
Every edit path now banks its pre-edit state, and the editor claims Cmd+Z /
Cmd+Shift+Z (plus Ctrl+Y) instead of letting the native command run. Snapshots
are plain text + a caret offset rather than DOM, since the editor already
round-trips losslessly through composerPlainText/renderComposerContents.
Consecutive keystrokes coalesce inside a 600ms window, so undo steps back by a
typing burst the way a native editor does rather than one character at a time.
Electron's Edit menu `{ role: 'undo' }` fires the native command without a
keystroke the renderer can see, so a capture-phase `beforeinput` listener claims
historyUndo/historyRedo too and keeps the menu item and the shortcut in
agreement. Switching drafts resets the history — undoing into another
conversation's text is worse than having none.
Co-authored-by: David Metcalfe <80915+DavidMetcalfe@users.noreply.github.com>
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…ct-delete (NousResearch#45812) Large paste and Ctrl+A → Delete froze the composer for seconds — both routed through Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM). - insertPlainTextAtCaret: Range + text/<br> fragment (paste path) - deleteSelectionInEditor: range.deleteContents for non-collapsed Backspace/Delete - Shared composerSelectionRange helper; both flush via flushEditorToDraft Profiled live (47 KB / 122 paragraphs): paste 4474 ms → 13 ms; select-delete 1304 ms → 4 ms. Collapsed-caret deletes still native.
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
The rich editor mutates its DOM through `Range` rather than the browser's
editing commands, because `execCommand('insertText')` is ~O(n²) on large
multiline blobs and froze the composer for seconds on a big paste (NousResearch#45812).
Those mutations never reach Chromium's undo stack, so a paste was invisible to
it — Cmd+Z skipped straight past the pasted text and undid whatever edit came
before it, leaving the paste stranded and the earlier edit destroyed.
Owning the stack outright is the only coherent fix; a half-owned one interleaves
our snapshots with Chromium's own typing entries and undoes them out of order.
Every edit path now banks its pre-edit state, and the editor claims Cmd+Z /
Cmd+Shift+Z (plus Ctrl+Y) instead of letting the native command run. Snapshots
are plain text + a caret offset rather than DOM, since the editor already
round-trips losslessly through composerPlainText/renderComposerContents.
Consecutive keystrokes coalesce inside a 600ms window, so undo steps back by a
typing burst the way a native editor does rather than one character at a time.
Electron's Edit menu `{ role: 'undo' }` fires the native command without a
keystroke the renderer can see, so a capture-phase `beforeinput` listener claims
historyUndo/historyRedo too and keeps the menu item and the shortcut in
agreement. Switching drafts resets the history — undoing into another
conversation's text is worse than having none.
Co-authored-by: David Metcalfe <80915+DavidMetcalfe@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Large paste and Ctrl+A → Delete froze the composer for seconds. Both hit Chromium's contenteditable editing pipeline (~O(n²) on multiline DOM) — a browser cost, same in prod.
Fix lives in
rich-editor.ts:insertPlainTextAtCaret— Range +text/<br>fragment (paste)deleteSelectionInEditor—range.deleteContents()for non-collapsed Backspace/DeletecomposerSelectionRange; composer flushes via existingflushEditorToDraftCollapsed-caret deletes (incl. Opt/Cmd word/line delete) still native.
Profiled live (47 KB / 122 paragraphs)
onPaste)Test plan
vitest run --environment jsdom rich-editor.test.ts— 7/7tsc --noEmitclean