fix: default collectedPercentage to 0 for non-finite values#51
Conversation
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>
There was a problem hiding this comment.
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-finitecollectedPercentvalues by falling back to0. - Make
StationService.getUnresolvedStations()return an empty list when the stations storage entry is absent (instead of throwing). - Default
StationService.getStation()’sstation.collectedPercentageto0when 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.
| if (!Number.isFinite(this.collectedPercent)) { | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
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.
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.