-
Notifications
You must be signed in to change notification settings - Fork 36k
Graph - fix case when the merge base is not yet fetched #275145
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
Conversation
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.
Pull Request Overview
This PR adds defensive checks to prevent array index access errors when creating incoming/outgoing changes nodes in the SCM history graph. The changes guard against scenarios where the merge base history item might not be loaded yet.
Key changes:
- Added validation to check that both
beforeHistoryItemIndexandafterHistoryItemIndexare valid (-1 check) before accessing array elements - Updated comments to clarify that indices might not be found if history items are not yet loaded
- Wrapped the incoming and outgoing changes node creation logic in conditional blocks
| // Create incoming changes node | ||
| const inputSwimlanes = viewModels[beforeHistoryItemIndex].outputSwimlanes.map(i => deepClone(i)); | ||
| const outputSwimlanes = viewModels[afterHistoryItemIndex].inputSwimlanes.map(i => deepClone(i)); | ||
| const displayIdLength = viewModels[0].historyItem.displayId?.length ?? 0; |
Copilot
AI
Nov 4, 2025
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.
Potential array access error: viewModels[0] can throw if the array is empty. Although the function builds viewModels from historyItems, this code is inside a guard that only checks beforeHistoryItemIndex !== -1 && afterHistoryItemIndex !== -1, which doesn't guarantee the array is non-empty. Consider adding a check viewModels.length > 0 or using optional chaining: viewModels[0]?.historyItem.displayId?.length ?? 0.
| const displayIdLength = viewModels[0].historyItem.displayId?.length ?? 0; | |
| const displayIdLength = viewModels[0]?.historyItem.displayId?.length ?? 0; |
| }) | ||
| : []; | ||
| const outputSwimlanes = viewModels[afterHistoryItemIndex].inputSwimlanes.slice(0); | ||
| const displayIdLength = viewModels[0].historyItem.displayId?.length ?? 0; |
Copilot
AI
Nov 4, 2025
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.
Potential array access error: viewModels[0] can throw if the array is empty. Although the function builds viewModels from historyItems, this code is inside a guard that only checks afterHistoryItemIndex !== -1, which doesn't guarantee the array is non-empty. Consider adding a check viewModels.length > 0 or using optional chaining: viewModels[0]?.historyItem.displayId?.length ?? 0.
| const displayIdLength = viewModels[0].historyItem.displayId?.length ?? 0; | |
| const displayIdLength = viewModels[0]?.historyItem.displayId?.length ?? 0; |
Fixes #275089