Skip to content

fix: default collectedPercentage to 0 for non-finite values#51

Merged
stefanhuber merged 1 commit into
mainfrom
fix-nan-collected-percentage
Apr 17, 2026
Merged

fix: default collectedPercentage to 0 for non-finite values#51
stefanhuber merged 1 commit into
mainfrom
fix-nan-collected-percentage

Conversation

@stefanhuber

Copy link
Copy Markdown
Member

Guard StationService.getStation and the station-icon progress ring against NaN, null, or undefined collectedPercentage values that would otherwise produce NaN aria-valuenow/stroke-dashoffset attributes in the rendered SVG.

Guard StationService.getStation and the station-icon progress ring
against NaN, null, or undefined collectedPercentage values that would
otherwise produce NaN aria-valuenow/stroke-dashoffset attributes in
the rendered SVG.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 17, 2026 19:33
@stefanhuber stefanhuber merged commit ec09c0c into main Apr 17, 2026
7 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens station collection progress handling by defaulting invalid progress values to 0, preventing NaN from leaking into rendered SVG attributes (e.g., aria-valuenow, stroke-dashoffset) and avoiding exceptions when optional storage keys are missing.

Changes:

  • Guard <sc-station-icon> progress calculations against non-finite collectedPercent values by falling back to 0.
  • Make StationService.getUnresolvedStations() return an empty list when the stations storage entry is absent (instead of throwing).
  • Default StationService.getStation()’s station.collectedPercentage to 0 when missing/null/NaN, and add tests/snapshots for these cases.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/ui/src/components/station-icon/station-icon.tsx Adds non-finite guard in percent calculation to prevent NaN in SVG/ARIA attributes.
packages/ui/src/components/station-icon/station-icon.snapshot.tsx Adds snapshot test covering NaN collectedPercent fallback behavior.
packages/ui/src/components/station-icon/snapshots/station-icon.snapshot.tsx.snap Updates snapshots to reflect the new NaN fallback rendering.
packages/data/src/domain/station/station-service.ts Prevents throws for missing stations-<lang> and normalizes invalid collectedPercentage on load.
packages/data/test/domain/station/service.test.ts Adds coverage for missing stations list and invalid collectedPercentage normalization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +37
if (!Number.isFinite(this.collectedPercent)) {
return 0;
}

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

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

calculatePercent() now normalizes non-finite collectedPercent to 0, but the collected/checkmark rendering condition later in render() still uses the raw this.collectedPercent >= this.upperLimitPercent. For values like Infinity, this will show the collected icon while the progress ring renders as 0%. Consider reusing the normalized percent value (or applying the same non-finite guard) for the collected/checkmark condition to keep UI consistent for all non-finite inputs.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants