-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(issues): improve similar issues stacktrace diff #97645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d5eb822
ref(issues): improve similar issues stacktrace diff
shayna-ch 7712043
add option to choose lines vs words in diff
shayna-ch 9c3416c
toggle switch
shayna-ch a6e7ee1
back to line
shayna-ch 8310f11
ref(grouping): fix similar issues diff
shayna-ch 0d9bd0f
don't use iife
shayna-ch 838caf7
actually remove iife
shayna-ch b6d10ba
wrap groupedChanges in useMemo
shayna-ch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,28 +26,71 @@ type Props = { | |
| function SplitDiff({className, type = 'lines', base, target}: Props) { | ||
| const diffFn = diffFnMap[type]; | ||
|
|
||
| const baseLines = base.split('\n'); | ||
| const targetLines = target.split('\n'); | ||
| const [largerArray] = | ||
| baseLines.length > targetLines.length | ||
| ? [baseLines, targetLines] | ||
| : [targetLines, baseLines]; | ||
| const results = largerArray.map((_line, index) => | ||
| diffFn(baseLines[index] || '', targetLines[index] || '', {newlineIsToken: true}) | ||
| ); | ||
| const results = diffFn(base, target, {newlineIsToken: true}); | ||
|
|
||
| // split one change that includes multiple lines into one change per line (for formatting) | ||
| const processResults = (): Change[][] => { | ||
| let currentLine: Change[] = []; | ||
| const processedLines: Change[][] = []; | ||
| for (const change of results) { | ||
| const lines = change.value.split('\n'); | ||
| for (let i = 0; i < lines.length; i++) { | ||
| const lineValue = lines[i]; | ||
| if (lineValue !== undefined && lineValue !== '') { | ||
| currentLine.push({ | ||
| value: lineValue, | ||
| added: change.added, | ||
| removed: change.removed, | ||
| }); | ||
| } | ||
| if (i < lines.length - 1) { | ||
| processedLines.push(currentLine); | ||
| currentLine = []; | ||
| } | ||
| } | ||
| } | ||
| if (currentLine.length > 0) { | ||
| processedLines.push(currentLine); | ||
| } | ||
| return processedLines; | ||
| }; | ||
|
||
|
|
||
| const groupedChanges = processResults(); | ||
|
|
||
| return ( | ||
| <SplitTable className={className} data-test-id="split-diff"> | ||
| <SplitBody> | ||
| {results.map((line, j) => { | ||
| {groupedChanges.map((line, j) => { | ||
| const highlightAdded = line.find(result => result.added); | ||
| const highlightRemoved = line.find(result => result.removed); | ||
|
|
||
| // Apply word-level diffing only to lines that have changes | ||
| const displayData = | ||
| highlightAdded || highlightRemoved | ||
| ? (() => { | ||
| const leftText = line.reduce( | ||
| (acc, result) => (result.added ? acc : acc + result.value), | ||
| '' | ||
| ); | ||
| const rightText = line.reduce( | ||
| (acc, result) => (result.removed ? acc : acc + result.value), | ||
| '' | ||
| ); | ||
|
|
||
| // Handle edge cases where text might be empty | ||
| if (!leftText && !rightText) { | ||
| return line; // Return original line if both texts are empty | ||
| } | ||
|
|
||
| return diffWords(leftText, rightText); | ||
| })() | ||
|
||
| : line; | ||
|
|
||
| return ( | ||
| <tr key={j}> | ||
| <Cell isRemoved={highlightRemoved}> | ||
| <Line> | ||
| {line | ||
| {displayData | ||
| .filter(result => !result.added) | ||
| .map((result, i) => ( | ||
| <Word key={i} isRemoved={result.removed}> | ||
|
|
@@ -61,7 +104,7 @@ function SplitDiff({className, type = 'lines', base, target}: Props) { | |
|
|
||
| <Cell isAdded={highlightAdded}> | ||
| <Line> | ||
| {line | ||
| {displayData | ||
| .filter(result => !result.removed) | ||
| .map((result, i) => ( | ||
| <Word key={i} isAdded={result.added}> | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Diff Visualization Errors in SplitDiff
The
processResultsfunction inSplitDiffhas two flaws: it incorrectly separates removed and added lines that are part of a replacement, preventing side-by-side diff visualization; and itslineValue !== ''check filters out empty lines, hiding changes involving blank lines and altering content structure in diffs.