fix(desktop): truncate large text paste to prevent UI freeze - #40159
Closed
thedavidweng wants to merge 1 commit into
Closed
fix(desktop): truncate large text paste to prevent UI freeze#40159thedavidweng wants to merge 1 commit into
thedavidweng wants to merge 1 commit into
Conversation
Pasting a large multi-line text (e.g. a full log file with thousands of lines) into the chat composer freezes the browser. The root cause is that document.execCommand inserts one DOM node per line into the contentEditable div, and the subsequent composerPlainText recursive walk plus React re-render on the huge state all run synchronously on the main thread. Add a MAX_PASTE_LENGTH (50,000 chars) hard limit in handlePaste. When the pasted text exceeds this threshold it is truncated before insertion and a warning notification is shown. This keeps the DOM manageable and prevents the freeze while still allowing large pastes up to a generous limit. Fixes NousResearch#40147
thedavidweng
force-pushed
the
fix/desktop-paste-large-text-freeze
branch
from
June 5, 2026 22:48
57b8f13 to
8b4d0cd
Compare
1 task
Contributor
|
Thanks for the report and focused fix. This is an automated hermes-sweeper review: current
|
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.
Problem
Pasting a large multi-line text (e.g. a full log file with thousands of lines) into the chat composer freezes the entire application. The UI becomes completely unresponsive and must be force-quit.
The root cause is that
document.execCommand('insertText')creates one DOM node per line in the contentEditable div, followed by a synchronous recursive DOM walk (composerPlainText) and a React state update — all on the main thread. For thousands of lines, this blocks the UI thread long enough to trigger a freeze.Fix
Add a
MAX_PASTE_LENGTH(50,000 characters) hard limit inhandlePaste. When the pasted text exceeds this threshold it is truncated before insertion and a warning notification is shown:This keeps the DOM manageable and prevents the freeze while still allowing large pastes up to a generous limit (roughly 1,000–2,000 lines depending on line length).
Changes
apps/desktop/src/app/chat/composer/index.tsx— addMAX_PASTE_LENGTHconstant and truncation logic inhandlePasteFixes #40147