Problem
MetricsDropdown.tsx and CompareV2.tsx hardcode [0] and [1] array indices to address the two comparison panels. There is no runtime guard if selectedArtifacts.length < 2, so any future change to the panel count (or a bug in the parent) would cause a silent crash.
Affected locations:
frontend/src/components/viewers/MetricsDropdown.tsx — 6 occurrences (selectedArtifacts[0], selectedArtifacts[1], selectedArtifactsForDisplay[0], selectedArtifactsForDisplay[1])
frontend/src/pages/CompareV2.tsx — getVerifiedTwoPanelSelection indexes [0]/[1], and createSelectedArtifactArray(2) seeds the magic number in 3 places
Suggested fix
- Extract the panel count into a named constant (e.g.
COMPARE_PANEL_COUNT = 2).
- Derive the dropdown layout from the array length rather than hardcoded indices where possible.
- Add a runtime assertion or early return if
selectedArtifacts.length doesn't match the expected count.
Context
Spotted during review of #13256. Pre-existing issue, not introduced by that PR.
Problem
MetricsDropdown.tsxandCompareV2.tsxhardcode[0]and[1]array indices to address the two comparison panels. There is no runtime guard ifselectedArtifacts.length < 2, so any future change to the panel count (or a bug in the parent) would cause a silent crash.Affected locations:
frontend/src/components/viewers/MetricsDropdown.tsx— 6 occurrences (selectedArtifacts[0],selectedArtifacts[1],selectedArtifactsForDisplay[0],selectedArtifactsForDisplay[1])frontend/src/pages/CompareV2.tsx—getVerifiedTwoPanelSelectionindexes[0]/[1], andcreateSelectedArtifactArray(2)seeds the magic number in 3 placesSuggested fix
COMPARE_PANEL_COUNT = 2).selectedArtifacts.lengthdoesn't match the expected count.Context
Spotted during review of #13256. Pre-existing issue, not introduced by that PR.