Skip to content

fix(diff): add line count guard to prevent large file diff from freezing UI#465

Merged
ErlichLiu merged 1 commit into
mainfrom
fix/diff-view-large-file-freeze
May 15, 2026
Merged

fix(diff): add line count guard to prevent large file diff from freezing UI#465
ErlichLiu merged 1 commit into
mainfrom
fix/diff-view-large-file-freeze

Conversation

@ErlichLiu
Copy link
Copy Markdown
Owner

Summary

Root Cause

@pierre/diffs MultiFileDiff internally calls createTwoFilesPatchdiffLines() (Myers O(N×D)) synchronously in useMemo, blocking the main thread. The parseDiffOptions type excludes timeout/maxEditLength, so the underlying diff library cannot be constrained.

Fix

  • countLines() helper efficiently counts newlines in O(chars)
  • If either old or new content exceeds 5000 lines, skip MultiFileDiff and show a clean fallback
  • Matches the existing MAX_PREVIEW_CHARS = 500_000 guard pattern in DiffTabContent.tsx

Test Plan

  • TypeScript compiles with no errors
  • Open a large file (>5000 lines) diff — should show fallback instead of freezing
  • Open a normal file diff — should render normally
  • Toggle between unified/split view with large files — no freeze

🤖 Generated with Claude Code

…ing UI

When the agent generates large files (e.g., in "visual companion" mode),
the Myers diff algorithm O(N*D) in @pierre/diffs blocks the main thread.
Skip MultiFileDiff rendering for files over 5000 lines and show a
fallback message instead.

Closes #459

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@ErlichLiu ErlichLiu merged commit 32f6931 into main May 15, 2026
@ErlichLiu ErlichLiu deleted the fix/diff-view-large-file-freeze branch May 15, 2026 04:53
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.

使用 brainstorming 时右侧文件改动面板引发应用未响应

1 participant