fix: handle undefined assignmentTypeGradeSummary in progress tab #1852
+10
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a runtime crash (white screen) occurring on the Progress tab in the Learning MFE.
The Issue:
After upgrading from Sumac to Ulmo, we observed that the
useModel('progress', ...)hook occasionally returnsundefinedor incomplete data during the initial render phase. This causesTypeErrorcrashes when the code attempts to access array methods (such as.some(),.length) or pass these variables to utility functions (likegetLatestDueDateInFuture).Specific errors observed in the console:
TypeError: Cannot read properties of undefined (reading 'some')inCurrentGradeTooltip.jsxTypeError: Cannot read properties of undefined (reading 'length')inGradeSummary.jsxTypeError: Cannot read properties of undefined (reading 'forEach')(via utils) inCourseGradeFooter.jsxThe Fix:
I have applied defensive coding practices by assigning default empty arrays (
[]) and objects ({}) to the destructured variables fromuseModel. This ensures that the components can render safely even if the API response is delayed or the model data is not yet fully populated.Changes
assignmentTypeGradeSummary,courseGrade, andgradeRange.assignmentTypeGradeSummaryandcourseGrade.assignmentTypeGradeSummaryto prevent.lengthcheck failure.Testing Instructions
TypeError: Cannot read properties of undefinederrors are logged related to grade summaries.