Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 20, 2025

Fix for NaN seed results in competition groups

Homepage after fix

  • Analyze the issue: NaN appears when renderResultByEventId receives undefined/null values
  • Identify root cause: Missing null/undefined checks in seedResult function before calling renderResultByEventId
  • Add null/undefined validation in seedResult function for previous round results
  • Add null/undefined validation in seedResult function for personal best results
  • Add defensive validation in renderResultByEventId function to handle null/undefined/NaN values
  • Create comprehensive tests to validate the fix (14 new test cases across 2 test files)
  • Validate fix by running all tests (22 tests passing)
  • Validate fix by building the application successfully
  • Validate fix by running the application locally

Changes Made

1. EventActivity.tsx: Added explicit null checks in seedResult function before passing values to renderResultByEventId

  • Check if prevRoundResults.average is null before rendering average results
  • Check if prevRoundResults.best is null before rendering single results
  • Check if personal best values are null before rendering

2. results.ts: Added defensive validation in renderResultByEventId function

  • Return empty string if result is null, undefined, or NaN
  • Prevents downstream functions from receiving invalid values

3. Added comprehensive tests: Created test suites to validate null/undefined handling

  • results.test.ts: Tests for the core rendering function (6 tests)
  • seedResult.test.ts: Tests for edge cases with mocked dependencies (8 tests)

Solution Summary

This fix ensures that instead of displaying "NaN" when result data is missing or invalid, the application will display an empty string, providing a cleaner user experience. The fix implements a two-layer defense:

  1. Prevention: Check for null/undefined values before calling renderResultByEventId
  2. Protection: Return empty string from renderResultByEventId if invalid values are received

The fix has been thoroughly tested with 14 new test cases covering all edge cases.

Fixes #17.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@netlify
Copy link

netlify bot commented Sep 20, 2025

Deploy Preview for competition-groups ready!

Name Link
🔨 Latest commit 227a83d
🔍 Latest deploy log https://app.netlify.com/projects/competition-groups/deploys/68cdfd27be191500082a6535
😎 Deploy Preview https://deploy-preview-47--competition-groups.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-authored-by: coder13 <881394+coder13@users.noreply.github.com>
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.

Seed result is NaN

2 participants