Summary
PriceChart renders 3 x-axis time labels (first, mid, last) using idx as the React key. When a token has only 1 or 2 trade records, lastIdx is 0 or 1, causing multiple labels to share idx: 0 — triggering React's duplicate key warning.
Steps to Reproduce
- Buy tokens for a storyline that has no prior trades
- After trade completes, observe browser console
- Warning:
Encountered two children with the same key, 'xl-0' at PriceChart.tsx:168
Root Cause
src/components/PriceChart.tsx:124-128:
const xLabels = [
{ idx: 0, label: formatTime(points[0].time) },
{ idx: Math.floor(lastIdx / 2), label: formatTime(points[Math.floor(lastIdx / 2)].time) },
{ idx: lastIdx, label: formatTime(points[lastIdx].time) },
];
When lastIdx = 0 (1 data point): all three entries have idx: 0.
When lastIdx = 1 (2 data points): first and mid both have idx: 0.
Fix
Deduplicate the label array by idx before rendering:
const xLabelCandidates = [
{ idx: 0, label: formatTime(points[0].time) },
{ idx: Math.floor(lastIdx / 2), label: formatTime(points[Math.floor(lastIdx / 2)].time) },
{ idx: lastIdx, label: formatTime(points[lastIdx].time) },
];
const xLabels = xLabelCandidates.filter(
(item, i, arr) => arr.findIndex((a) => a.idx === item.idx) === i,
);
Files to Change
| File |
Change |
src/components/PriceChart.tsx |
Deduplicate xLabels array by idx |
Acceptance Criteria
Branch
task/{issue-number}-pricechart-dedup-keys
Summary
PriceChart renders 3 x-axis time labels (first, mid, last) using
idxas the React key. When a token has only 1 or 2 trade records,lastIdxis 0 or 1, causing multiple labels to shareidx: 0— triggering React's duplicate key warning.Steps to Reproduce
Encountered two children with the same key, 'xl-0'atPriceChart.tsx:168Root Cause
src/components/PriceChart.tsx:124-128:When
lastIdx = 0(1 data point): all three entries haveidx: 0.When
lastIdx = 1(2 data points): first and mid both haveidx: 0.Fix
Deduplicate the label array by
idxbefore rendering:Files to Change
src/components/PriceChart.tsxxLabelsarray byidxAcceptance Criteria
npm run typecheckpassesnpm run lintpassesBranch
task/{issue-number}-pricechart-dedup-keys