fix: prevent page crashes when mock-fcc-data server is offline
Checklist:
- [x] I have read freeCodeCamp's contribution guidelines.
- [x] My pull request has a [descriptive title](not a vague title like
Update index.md)
Closes #533
Description of Changes
This PR resolves page crashes (like on /dashboard and /dashboard/v2/details) when the mock-fcc-data JSON server is not running or the MOCK_USER_DATA_URL environment variable is missing.
Key changes include:
- Graceful API Fetch Failure: Wrapped the main mock student dataset fetch in
try/catchblocks insideutil/student/fetchStudentData.js, defaulting to an empty array ([]) and warning/logging the error instead of throwing uncaught runtime exceptions. - Defensive Parameter Checks: Added type checking (
Array.isArray()) and truthiness safety guards to traversal utility methods (getStudentProgressInSuperblock,extractStudentCompletionTimestamps,extractFilteredCompletionTimestamps, andcheckIfStudentHasProgressDataForSuperblocksSelectedByTeacher) to handle empty fallback student data cleanly. - Resilient Dashboard Rendering: Added checks to the student loop inside
pages/dashboard/v2/[id].jsto prevent crashing whenstudentDataor certification options are empty.
Thank you for the review and the detailed feedback!
I'll remove the unrelated changes from navbar.js, [...nextauth].js, and navbar.test.jsx and update the PR accordingly. I'll also address the comments regarding the null-proof checks and the forEach index optimization. Regarding the fetch error handling suggestion, I agree that returning distinct error codes would provide better visibility into the failure state. Since the current implementation resolves the crash issue, I can either incorporate that enhancement in this PR if preferred or handle it as a follow-up issue.
Thanks again for the suggestions!
Hey @utsab ! Can u please review this pr, NewtonLC reviewed and is satisfied with my changes
Hi @AbiramiR-27!
Right now, we're working with the FreeCodeCamp maintainers to get the stack deployed, which will involve student and teacher onboarding workflows (PRs #595 and #600). Once that's in place, we'll be able to review both of your PRs. Thanks again for working on them, and for sticking with the Classroom app project!
Thanks for the update! I understand. Thanks again!
Hi @utsab @NewtonLC , just following up to see if you have any updates on this PR.