fix: handle missing author in deleted content to prevent frontend crash#17
fix: handle missing author in deleted content to prevent frontend crash#17
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a frontend crash that occurs when the discussions API returns deleted content with a null author value. The fix adds defensive null checks to the AuthorLabel component to handle cases where author data is missing or null.
Changes:
- Made the
authorprop optional in AuthorLabel component - Added null-safe rendering logic with a "[Deleted User]" fallback display
- Prevented profile link generation when author is null
- Added comprehensive defaultProps for all optional props
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| AuthorLabel.defaultProps = { | ||
| author: null, | ||
| authorLabel: null, | ||
| linkToProfile: false, | ||
| labelColor: '', | ||
| alert: false, | ||
| postCreatedAt: null, | ||
| authorToolTip: false, | ||
| postOrComment: false, | ||
| postData: null, | ||
| }; |
There was a problem hiding this comment.
Test coverage should be added to verify that AuthorLabel handles null author values correctly. Consider adding test cases for:
- Rendering with null author (should display '[Deleted User]')
- Styling behavior when author is null (should use 'text-gray-700')
- No link generation when author is null
This is important because the change allows null author values which is a new behavior that should be tested.
fd7c2d1 to
6a23c57
Compare
8abb4c8 to
c620db5
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it('should not generate a link when author is null even with linkToProfile=true', () => { | ||
| renderComponent(null, null, true, '', false); | ||
| expect(screen.queryByTestId('learner-posts-link')).not.toBeInTheDocument(); | ||
| }); |
There was a problem hiding this comment.
This test appears to be redundant with the test on line 263-266. Both tests verify that no link is generated when author is null and linkToProfile is true. The only difference is that this test explicitly passes enableInContextSidebar=false as the 5th parameter, but that doesn't materially change what's being tested. Consider removing this duplicate test or modifying it to test a different scenario.
c620db5 to
f073a2e
Compare
Description
In stage, the frontend crashes for some courses when rendering deleted discussion content. The deleted content API may return a null author, but the frontend unconditionally attempts to generate an author profile URL, resulting in a runtime error.
Root Cause
The frontend assumes author data is always present.
There is no guard for null author values when generating profile links.
Changes
Add defensive checks to safely handle deleted content with missing or null author data.
Avoid generating profile URLs when author information is unavailable.
Ticket
COSMO2-808
Related PR : edx/edx-platform#109