Skip to content

bug: Unguarded optional-field access can white-screen the mentors and landing pages #302

Description

@yingliu-data

Bug Report

Unguarded property access can white-screen the whole mentors page and the landing page when a record omits optional fields (the backend serializes with JsonInclude.NON_NULL, so absent fields arrive as missing keys).

  • src/components/MentorProfileCard.tsx — line 98 mentor.images[0]?.path (throws if images itself is absent), line 187 mentor.country.countryName, line 190 mentor.network.map(...), line 226 mentor.skills.yearsExperience (line 114 defensively uses skills?. but 226 doesn't), line 230 mentor.spokenLanguages.length, line 271 mentor.menteeSection.additional.
  • src/components/EventContainer.tsx:65 event.endDate.split(', '), line 71 event.speakerProfile.label; src/components/EventCard.tsx:67,77 images[0].path. Backend Event.speakerProfile is nullable.

Reproduction

  • A mentor record with a null network/images/country → one bad mentor throws during render → the entire /mentorship/mentors list white-screens.
  • A CMS event with no speaker/images/endDate → the home page throws during render (SSR 500 / client crash).

Severity

Medium

Potential Risk

  • A single sparse record takes down an entire public page.

Suggested Fix

  • Guard all optional-field access with optional chaining / defaults, consistently (e.g. mentor.images?.[0]?.path, mentor.network?.map, event.speakerProfile?.label).
  • Consider normalizing API responses (default missing arrays to []) at the fetch boundary.
  • Add tests rendering mentor/event cards from minimal payloads.

Registration-side complement to #271 (rendering existing images); this covers crashes on sparse data across cards.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions