📋 Description
components/Insights/categoryDonutChart.tsx and components/Insights/spendingVsSavingChart.tsx recompute derived data (totals, center labels, transformed datasets) and define inline CustomTooltip/CustomLegend components on every render, without useMemo/React.memo. Recharts re-renders are already expensive, and these are mounted together on app/insights/page.tsx.
Why this matters: the Insights page mounts several heavy charts at once; recomputing derived series and recreating tooltip/legend components each render multiplies Recharts' reconciliation cost and causes visible jank on lower-end devices. Memoizing the inputs and subcomponents is a measurable, low-risk performance win.
🎯 Requirements & Context
Functional requirements
Context & constraints
- Recharts
3.7.0; do not change chart visuals — this is a perf refactor.
- Coordinate with the chart-crash fix if both are in flight (rebase on it).
🛠️ Suggested Execution
1. Fork & branch
git checkout -b perf/memoize-insights-charts
2. Implement changes
- Add memoization, hoist subcomponents, and add a render test asserting stable output.
- Document the memoization rationale in TSDoc on the derived-data hooks.
3. Test & commit
npx tsc --noEmit
npm run lint
npm run test:coverage
- Cover edge cases: empty datasets, single category, reduced-motion, and resizing (ResponsiveContainer) without thrashing.
Example commit message
perf(insights): memoize donut + spending/savings charts and subcomponents
Avoids per-render recomputation of derived series and recreating tooltip/legend.
✅ Acceptance Criteria & Guidelines
| Requirement |
Target |
| Derived data + subcomponents memoized |
Required |
| No visual/behavior change |
Required |
| Render test added |
Required |
| Accessibility preserved |
Required |
npx tsc --noEmit, npm run lint, npm run build clean |
Required |
| Timeframe |
96 hours from assignment |
💬 Community & Support
Join the RemitWise contributor community on Discord: https://discord.gg/CtQuPZFMA
Please comment when you pick this up so we can avoid duplicate work. 🚀
📋 Description
components/Insights/categoryDonutChart.tsxandcomponents/Insights/spendingVsSavingChart.tsxrecompute derived data (totals, center labels, transformed datasets) and define inlineCustomTooltip/CustomLegendcomponents on every render, withoutuseMemo/React.memo. Recharts re-renders are already expensive, and these are mounted together onapp/insights/page.tsx.🎯 Requirements & Context
Functional requirements
useMemowith correct dependency arrays in both chart files.CustomTooltip/CustomLegendso they aren't re-created every render (define outside the component or wrap inReact.memo/useCallback).React.memowhere props are referentially stable.sr-onlyaccessible summaries and the color-blind-safe palette fromcomponents/Insights/palette.tsintact.Context & constraints
3.7.0; do not change chart visuals — this is a perf refactor.🛠️ Suggested Execution
1. Fork & branch
2. Implement changes
3. Test & commit
Example commit message
✅ Acceptance Criteria & Guidelines
npx tsc --noEmit,npm run lint,npm run buildclean💬 Community & Support
Join the RemitWise contributor community on Discord: https://discord.gg/CtQuPZFMA
Please comment when you pick this up so we can avoid duplicate work. 🚀