Skip to content

fix(desktop): truncate large text paste to prevent UI freeze - #40159

Closed
thedavidweng wants to merge 1 commit into
NousResearch:mainfrom
thedavidweng:fix/desktop-paste-large-text-freeze
Closed

fix(desktop): truncate large text paste to prevent UI freeze#40159
thedavidweng wants to merge 1 commit into
NousResearch:mainfrom
thedavidweng:fix/desktop-paste-large-text-freeze

Conversation

@thedavidweng

Copy link
Copy Markdown
Contributor

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 in handlePaste. When the pasted text exceeds this threshold it is truncated before insertion and a warning notification is shown:

"Paste truncated — Text was truncated to 50,000 characters."

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 — add MAX_PASTE_LENGTH constant and truncation logic in handlePaste

Fixes #40147

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
thedavidweng force-pushed the fix/desktop-paste-large-text-freeze branch from 57b8f13 to 8b4d0cd Compare June 5, 2026 22:48
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Jun 5, 2026
@alt-glitch alt-glitch added comp/desktop Electron desktop app (apps/desktop/*) and removed comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Jun 26, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the report and focused fix. This is an automated hermes-sweeper review: current main already resolves the large multiline-paste freeze without truncating user input.

  • 0a865e5948cb836eba93620e365703ec38cf76e3 (fix(desktop): bypass Chromium editing pipeline for large paste & select-delete, fix(desktop): bypass Chromium editing pipeline for large paste & select-delete #45812) replaced the Chromium execCommand('insertText') path targeted by this PR.
  • Current apps/desktop/src/app/chat/composer/index.tsx:359-361 prevents the native paste, inserts via insertPlainTextAtCaret, and coalesces the draft flush.
  • apps/desktop/src/app/chat/composer/rich-editor.ts:147-173 implements that helper with a Range and text/<br> fragment, specifically avoiding Chromium's quadratic multiline editing path.
  • Regression coverage is present in apps/desktop/src/app/chat/composer/rich-editor.test.ts:75-110.
  • The linked issue [Bug]: Desktop app freezes when pasting large multi-line text into composer #40147 was already closed with the same verified implementation; the fix shipped in v2026.6.19.

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop app freezes when pasting large multi-line text into composer

3 participants