fix: stabilize diff panel rendering and hunk-safe truncation - #1737
Merged
Merged
Conversation
maxLines slicing cut patch text mid-hunk, leaving hunk headers that declared more body lines than were present. @pierre/diffs logged parsePatchContent count mismatches and repaired hunks with shifted boundaries, corrupting the rendered line mapping. Add truncateUnifiedDiff to @mcode/shared: keeps only complete hunks, drops a file header block when none of its hunks fit, and handles no-newline markers, countless/zero-count headers, and blank context lines. Applied to snapshot and git comparison diff reads, including the root-commit fallback.
The fileDiffs memo re-parsed every patch into a fresh FileDiffMetadata on any patches change while stamping the same cacheKey. Pierre's areDiffTargetsEqual treats same-key objects as one render target, so the virtualizer could prepare layout for the old object and commit the new one, tripping the 'rendered a different diff than its prepared layout' assertion during scroll and resize and crashing the panel. FileDiffCache reuses the parsed object while (scope, path, patch) are unchanged and gives every fresh parse a unique serial key, keeping object identity and render-target identity equivalent.
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.
What
The diff review panel crashed with
VirtualizedFileDiff.render: rendered a different diff than its prepared layoutand eventually took down the renderer, and the console filled withparsePatchContent: hunk line count mismatchwarnings. Two independent defects:ReviewDiffViewre-parsed every patch into a freshFileDiffMetadataobject on any state change while stamping the samecacheKey. Pierre'sareDiffTargetsEqualtreats same-key objects as one render target, so the virtualizer could prepare layout for the old object and commit the new one during scroll/resize, tripping its identity assertion. Fixed withFileDiffCache, which reuses the parsed object while the patch is unchanged and gives every fresh parse a unique serial key.maxLinestruncation sliced unified diffs mid-hunk, producing headers that declared more lines than were present. Pierre warned and repaired hunks with shifted boundaries. Fixed withtruncateUnifiedDiff, which keeps only complete hunks at all four truncation sites (snapshot service, commit diff, working-tree diff, branch diff, including the root-commit fallback).Why
The panel errored continuously while open until it hit the error boundary and crashed the app, and truncated inline diffs in chat rendered with corrupted hunk boundaries.
UI Changes
After: the Review panel renders the virtualized diff and survives scroll/resize/view switching with zero console errors (live-verified in Electron; screenshot could not be attached because this gh version lacks
pr create --attach, and.dev/is gitignored).Before: renderer crashed to the app error boundary after repeated
VirtualizedFileDiff.rendererrors (from production logs; no pre-fix screenshot captured).Config Changes
None.
Review Notes
git.workingTreeDiffwithmaxLines=500returned an incomplete hunk before the fix and hunk-bounded output after.truncateUnifiedDiffhandles\ No newlinemarkers,@@ -1 +1 @@countless headers, zero counts, and bare-empty context lines (diff.suppressBlankEmpty).DiffViewer's "Show full diff" check can never trigger since the response was already capped before this change; a file whose first hunk alone exceeds the budget now renders empty instead of a corrupt partial diff. A truncation flag in the RPC contract would be the proper fix.packages/sharedtruncate-patch suite,apps/webfile-diff-cache suite, plus existing snapshot/git-comparison/diff-panel suites all pass; lint and typecheck clean.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.