Skip to content

fix: handle missing author in deleted content to prevent frontend crash#17

Merged
Alam-2U merged 1 commit intomasterfrom
ealam/COSMO2-808
Feb 4, 2026
Merged

fix: handle missing author in deleted content to prevent frontend crash#17
Alam-2U merged 1 commit intomasterfrom
ealam/COSMO2-808

Conversation

@Alam-2U
Copy link

@Alam-2U Alam-2U commented Feb 2, 2026

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

@Alam-2U Alam-2U marked this pull request as ready for review February 2, 2026 11:53
Copilot AI review requested due to automatic review settings February 2, 2026 11:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 author prop 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.

Comment on lines +243 to +253
AuthorLabel.defaultProps = {
author: null,
authorLabel: null,
linkToProfile: false,
labelColor: '',
alert: false,
postCreatedAt: null,
authorToolTip: false,
postOrComment: false,
postData: null,
};
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage should be added to verify that AuthorLabel handles null author values correctly. Consider adding test cases for:

  1. Rendering with null author (should display '[Deleted User]')
  2. Styling behavior when author is null (should use 'text-gray-700')
  3. 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.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the testcases

Copilot AI review requested due to automatic review settings February 4, 2026 04:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +268 to +271
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();
});
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@Alam-2U Alam-2U merged commit 83529d3 into master Feb 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants