Skip to content

🐛 fix: guard against division by zero in StockMarketTicker portfolio summary#13076

Merged
kubestellar-hive[bot] merged 1 commit into
kubestellar:mainfrom
sshekhar563:fix/stock-ticker-division-by-zero
May 11, 2026
Merged

🐛 fix: guard against division by zero in StockMarketTicker portfolio summary#13076
kubestellar-hive[bot] merged 1 commit into
kubestellar:mainfrom
sshekhar563:fix/stock-ticker-division-by-zero

Conversation

@sshekhar563
Copy link
Copy Markdown
Contributor

@sshekhar563 sshekhar563 commented May 11, 2026

Fixes #13074

What

Guard stockData.length before dividing to prevent NaN when the array is empty.

Why

When stockData is [] (initial render with initialData: [] at line 555, or after the user removes all stocks), totalChange / stockData.length evaluates to 0 / 0 = NaN. This NaN propagates into the rendered portfolio summary.

Fix

- const avgChange = totalChange / stockData.length
+ const avgChange = stockData.length > 0 ? totalChange / stockData.length : 0
Copilot AI review requested due to automatic review settings May 11, 2026 09:40
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: no Indicates the PR's author has not signed the DCO. label May 11, 2026
@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign eeshaansa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions
Copy link
Copy Markdown
Contributor

👋 Hey @sshekhar563 — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow Bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

👋 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:

  • DCO Sign-off — All commits signed with git commit -s (DCO)
  • PR Title — Starts with an emoji: ✨ feature | 🐛 bug fix | 📖 docs | 🌱 infra/tests | ⚠️ breaking

📬 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.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 11, 2026

Deploy Preview for kubestellarconsole canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 9bd2cd1
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a01aaf98906f800083a4d37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 avgChange to avoid 0 / 0 producing NaN.
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
@kubestellar-hive
Copy link
Copy Markdown
Contributor

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-lease

The -s flag adds the required Signed-off-by: Your Name <your@email.com> line. Let me know if you have any questions!

@kubestellar-hive
Copy link
Copy Markdown
Contributor

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>
@sshekhar563 sshekhar563 force-pushed the fix/stock-ticker-division-by-zero branch from 2be1be3 to 9bd2cd1 Compare May 11, 2026 10:09
@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. and removed dco-signoff: no Indicates the PR's author has not signed the DCO. labels May 11, 2026
@sshekhar563 sshekhar563 changed the title fix: guard against division by zero in StockMarketTicker portfolio su… 🐛 fix: guard against division by zero in StockMarketTicker portfolio summary May 11, 2026
Copy link
Copy Markdown
Contributor

@kubestellar-hive kubestellar-hive Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix — guards empty array division correctly. LGTM.

@kubestellar-prow
Copy link
Copy Markdown
Contributor

@kubestellar-hive[bot]: changing LGTM is restricted to collaborators

Details

In response to this:

Clean fix — guards empty array division correctly. LGTM.

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.

@kubestellar-hive kubestellar-hive Bot merged commit 11630fe into kubestellar:main May 11, 2026
31 of 35 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

✅ Post-Merge Verification: passed

Commit: 11630fe2f92d2d5c291f8d523b98004cc1f6d85b
Specs run: Dashboard.spec.ts smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/25664747081

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. tier/2-standard

2 participants