feat: Handle nullable page field from MITx Online client update#3349
feat: Handle nullable page field from MITx Online client update#3349zamanafzal wants to merge 4 commits into
Conversation
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
There was a problem hiding this comment.
Pull request overview
This PR updates the MITx Online API client to a build where product page fields are nullable, and adjusts MITx Online product/dashboard UI code to avoid crashing when those fields are null.
Changes:
- Replaces direct
pageproperty reads with optional chaining/fallbacks in course, program, program-as-course, summary, and dashboard components. - Adds regression tests for nullable
pagedata in affected product/dashboard views. - Updates the MITx Online API client dependency and lockfile resolution to the pre-release tarball.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
frontends/api/package.json |
Points API workspace to updated MITx Online API client tarball. |
frontends/main/package.json |
Points main workspace to updated MITx Online API client tarball. |
yarn.lock |
Locks the updated MITx Online API client tarball/checksum. |
frontends/main/src/app-pages/ProductPages/CoursePage.tsx |
Guards nullable course page image/description access. |
frontends/main/src/app-pages/ProductPages/CoursePage.test.tsx |
Adds nullable course page regression test. |
frontends/main/src/app-pages/ProductPages/ProgramPage.tsx |
Guards nullable program page image/description access. |
frontends/main/src/app-pages/ProductPages/ProgramPage.test.tsx |
Adds nullable program page regression test. |
frontends/main/src/app-pages/ProductPages/ProgramAsCoursePage.tsx |
Guards nullable program-as-course page image/description access. |
frontends/main/src/app-pages/ProductPages/ProgramAsCoursePage.test.tsx |
Adds nullable program-as-course page regression test. |
frontends/main/src/app-pages/ProductPages/ProductSummary.tsx |
Guards nullable program page summary and financial assistance fields. |
frontends/main/src/app-pages/ProductPages/ProductSummary.test.tsx |
Adds nullable program page summary regression test. |
frontends/main/src/app-pages/DashboardPage/ContractContent.tsx |
Guards nullable dashboard program description access. |
frontends/main/src/app-pages/DashboardPage/ContractContent.test.tsx |
Adds nullable dashboard program page regression test. |
| }, | ||
| "dependencies": { | ||
| "@mitodl/mitxonline-api-axios": "2026.5.1", | ||
| "@mitodl/mitxonline-api-axios": "https://github.com/mitodl/mitxonline-api-clients/raw/96cb88a7aeac5ec38aeaf688b0784a0abeb7af47/src/typescript/mitxonline-api-axios/package.tgz", |
There was a problem hiding this comment.
Hey, quick question on the @mitodl/mitxonline-api-axios dependency. Is this GitHub tarball URL temporary while we wait for the updated package to be published to npm? Just want to make sure we swap it back to a version string before this merges so CI stays relia
There was a problem hiding this comment.
Yes, that's right. This is temporary utl, just to test the changes. I'll update the version first and then merge this PR.
daniellefrappier18
left a comment
There was a problem hiding this comment.
This looks good I was able to verify all the test cases, but please see my comment on the @mitodl/mitxonline-api-axios dependency before merging.
87121de to
f540d89
Compare
What are the relevant tickets?
https://github.com/mitodl/hq/issues/10652
mitodl/mitxonline#3426 (comment)
Description (What does it do?)
Bumps
@mitodl/mitxonline-api-axiosto a pre-release build frommitxonline#3426, which
corrects the OpenAPI spec so that the
pagefield onV2Program,V2ProgramDetail,V2Course, andCourseWithCourseRunsSerializerV2isnow typed as
T | null.Once the changes are validated in this PR, we will merge the mitodl/mitxonline#3426 and use the latest mitxonline-api-clients version instead of the pre-release.
Why the type change? The API was already returning
nullforpageon courses/programs without a Wagtail CMS page — the spec just wasn't
reflecting it. The v2 programs serializer was also returning an
inconsistent fallback object (
{"feature_image_src": url}) instead ofnull; that is removed in the upstream PR.This PR guards every
pagefield access with optional chaining soresources without a linked CMS page render gracefully instead of crashing.
Changes
ContractContent.tsxprogram.page?.descriptionCoursePage.tsxpage.course_details.page?.feature_image_src,?.descriptionProgramPage.tsxpage.program_details.page?.feature_image_src,?.descriptionProgramAsCoursePage.tsxpage.program_details.page?.feature_image_src,?.descriptionProductSummary.tsxpage?.length,page?.effort,page?.financial_assistance_form_urlScreenshots (if appropriate):
How can this be tested?
Page loads without crash, falls back to default placeholder image, description is empty:
Product page with CMS page: Hero image, description, and info box all render correctly.

Start Services
Terminal 1 — MITx Online
cd /path/to/mitxonline docker compose upTerminal 2 — MIT Learn
cd /path/to/mit-learn docker compose upBackpopulate MITx Online Data
From
mit-learn/:Select a Test Program
Pick any published program from the backpopulate output, or find one manually:
Test A — Unit Tests
Covers the
page === nullscenario end-to-end.Expected Result
Test B — Baseline Program With Full CMS Page
Visit:
Expected Result
Test C — Program With
feature_image_src: nullThis test removes the hero image from a program CMS page so
feature_image_srcreturnsnull, exercising the image fallback guard.3a. In MITx Online — Remove the Program Image
From
mitxonline/:3b. In MIT Learn — Sync the Change
3c. Visit the Program URL
Expected Result
TypeErrorin browser console3d. Restore the Image
Back in the MITx Online shell from step 3a:
Then re-sync MIT Learn:
Test D — Dashboard With Program That Has No CMS Page
This tests
ContractContentwhereprogram.pageis genuinelynullat runtime. This reads the MITx Online Programs API directly rather than
MIT Learn's database.
4a. In MITx Online — Create a Program With No Page
4b. Verify Dashboard Behavior
Log into MIT Learn as the enrolled test user and visit:
Find the no-page program in the enrolled programs list.
Expected Result
TypeError: Cannot read properties of nullin console