Skip to content

fix: diff display edge cases for empty patches and hunks#1247

Closed
bonerush wants to merge 1 commit into
claude-code-best:mainfrom
bonerush:fix/diff-empty-patch
Closed

fix: diff display edge cases for empty patches and hunks#1247
bonerush wants to merge 1 commit into
claude-code-best:mainfrom
bonerush:fix/diff-empty-patch

Conversation

@bonerush
Copy link
Copy Markdown
Contributor

@bonerush bonerush commented May 26, 2026

  • FileEditToolDiff: show "No changes to display" when patch is empty

  • FileWriteToolDiff: guard against empty hunks array

  • getPatchForDisplay: skip replace when old_string is empty

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of empty diffs by displaying a clear "No changes to display" message instead of an empty list.
    • Enhanced diff display logic to gracefully render original code when no hunks are available.
    • Fixed edit application for insert-only operations to properly handle empty source content.

Review Change Stack

- FileEditToolDiff: show "No changes to display" when patch is empty

- FileWriteToolDiff: guard against empty hunks array

- getPatchForDisplay: skip replace when old_string is empty
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b7ba6b97-d1be-4458-8f19-cd1ebee3b746

📥 Commits

Reviewing files that changed from the base of the PR and between c982104 and 56828e1.

📒 Files selected for processing (3)
  • src/components/FileEditToolDiff.tsx
  • src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx
  • src/utils/diff.ts

📝 Walkthrough

Walkthrough

This PR adds edge-case handling for empty and insert-only diffs. The utility function now correctly handles edits where old content is empty, and the diff rendering components gracefully display placeholders or fall back to syntax highlighting when no hunks exist.

Changes

Empty diff handling and insert-only edits

Layer / File(s) Summary
Patch generation for insert-only edits
src/utils/diff.ts
When an edit's old string is empty after escaping, getPatchForDisplay now returns the escaped new string directly instead of attempting a replace operation.
Component rendering for empty diffs
src/components/FileEditToolDiff.tsx, src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx
DiffBody and FileWriteToolDiff now check for empty patch or hunk lists, rendering "No changes to display" placeholders or falling back to HighlightedCode instead of rendering empty diff structures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A diff with nothing to compare,
No hunks, no patches in the air—
Now shows a message calm and bright:
"No changes," whispered soft and light.
Insert-only edits find their way,
Through empty strings to save the day! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: diff display edge cases for empty patches and hunks' accurately and specifically describes the main changes: handling empty patches in FileEditToolDiff, empty hunks in FileWriteToolDiff, and empty old_string in getPatchForDisplay.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bonerush bonerush closed this May 26, 2026
@bonerush bonerush deleted the fix/diff-empty-patch branch May 26, 2026 08:52
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.

1 participant