🐛 fix: guard against division by zero in StockMarketTicker portfolio summary#13076
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
👋 Hey @sshekhar563 — thanks for opening this PR!
This is an automated message. |
|
👋 Welcome to the KubeStellar community! 💖 Thanks and congrats 🎉 for opening your first PR here! We're excited to have you contributing. Before merge, please ensure:
📬 If you're using KubeStellar in your organization, please add your name to our Adopters list. 🙏 It really helps the project gain momentum and credibility — a small contribution back with a big impact. Resources:
A maintainer will review your PR soon. Hope you have a great time here! 🌟 ~~~~~~~~~~ 🌟 📬 If you like KubeStellar, please ⭐ star ⭐ our repo to support it! 🙏 It really helps the project gain momentum and credibility — a small contribution back with a big impact. |
✅ Deploy Preview for kubestellarconsole canceled.Built without sensitive environment variables
|
There was a problem hiding this comment.
Pull request overview
Prevents NaN from rendering in the Stock Market Ticker card’s portfolio summary by guarding the average-change calculation when there are zero tracked stocks.
Changes:
- Add a zero-length guard when computing
avgChangeto avoid0 / 0producingNaN.
| const portfolioSummary = useMemo(() => { | ||
| const totalChange = stockData.reduce((sum, stock) => sum + stock.changePercent, 0) | ||
| const avgChange = totalChange / stockData.length | ||
| const avgChange = stockData.length > 0 ? totalChange / stockData.length : 0 |
| const portfolioSummary = useMemo(() => { | ||
| const totalChange = stockData.reduce((sum, stock) => sum + stock.changePercent, 0) | ||
| const avgChange = totalChange / stockData.length | ||
| const avgChange = stockData.length > 0 ? totalChange / stockData.length : 0 |
|
Hi @sshekhar563 👋 Thanks for this fix! It looks like the DCO (Developer Certificate of Origin) check is failing. All commits need to be signed off. You can fix this by amending your commit: git commit --amend -s
git push --force-with-leaseThe |
|
Thanks for the fix! The DCO check is failing — your commit needs a sign-off. Please amend and force-push: git commit --amend -s --no-edit
git push --force-with-lease |
…mmary When stockData is an empty array (initial load before useCache resolves, or after the user removes all stocks), dividing totalChange by stockData.length produces NaN, which renders as literal NaN in the UI. Add a length guard to return 0 instead. Fixes kubestellar#13074 Signed-off-by: sshekhar563 <shekharsiddhant93@gmail.com>
2be1be3 to
9bd2cd1
Compare
|
@kubestellar-hive[bot]: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
11630fe
into
kubestellar:main
✅ Post-Merge Verification: passedCommit: |
Fixes #13074
What
Guard
stockData.lengthbefore dividing to preventNaNwhen the array is empty.Why
When
stockDatais[](initial render withinitialData: []at line 555, or after the user removes all stocks),totalChange / stockData.lengthevaluates to0 / 0 = NaN. ThisNaNpropagates into the rendered portfolio summary.Fix