fix(site/src/pages/AgentsPage/components/DiffViewer): dedupe diff files to prevent CodeView duplicate id crash#26597
Merged
Conversation
…es to prevent CodeView duplicate id crash
sreya
approved these changes
Jun 23, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Viewing a git diff on
/agentscould crash the whole diff view withCodeView.addItem: duplicate id "agent/x/agentmcp/api_internal_test.go". When a diff body lists the same post-image path in more than onediff --gitsection,parsePatchFilesreturns oneFileDiffMetadataper section.DiffViewerthen maps each file to aCodeViewitem keyed byfile.name(the file tree is likewise keyed by path), so the repeated path produced two items with the same id andCodeView.addItemthrew, tearing down the entire view.Deduplicate the parsed files by path in
useParsedDiff, keeping the first occurrence, so both theCodeViewand the file tree always receive unique ids.useParsedDiffis the single source feeding both panels, so a malformed diff now degrades gracefully and logs one warning instead of crashing.Root cause and verification
Confirmed against
@pierre/diffsparsePatchFilesthat a single patch with twodiff --gitsections for one path yieldspatchCount: 1,fileCount: 2with both entries namedagent/x/agentmcp/api_internal_test.go. That is the exact input that madeCodeView.addItemthrow. Dropping (rather than merging) duplicates matches the renderer's model, which can only show one item per id anyway.Verified on the branch:
pnpm test(DiffViewer suite, including the newdedupeFilesByNametests),tsc -p ., and the fullpnpm lint(biome, types, circular-deps, React Compiler, knip) all pass.