-
Notifications
You must be signed in to change notification settings - Fork 93
fix: prevent generatePath error when author is invalid in AuthorLabel #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prevent generatePath error when author is invalid in AuthorLabel #821
Conversation
|
Thanks for the pull request, @blarghmatey! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
|
@blarghmatey can you fix the tests? |
|
@taimoor-ahmed-1 the failing test on this branch appears to be unrelated to my changes and is currently failing on master as well. https://github.com/openedx/frontend-app-discussions/actions/runs/18284320993/job/52055073479 |
|
I have successfully deployed this branch to our production environment and verified that it fully resolves #817 The issue was not with retired users, though I suspect that it may be due to differences with how the Mongo and MySQL manage pagination? |
|
Can someone from the @openedx/committers-edx-platform-2u-infinity with merge access review this PR? |
|
@brian-smith-tcril or @arbrandes could you take a look at this? It needs to get into the release. |
|
Couple of notes/questions:
|
|
I imagine that As far as tests, the failing test is failing from the main branch and is unrelated to this change. If someone wants to fix it on master I'm happy to rebase. |
|
@blarghmatey I merged #775 and CI is passing on |
Wrap learnerPostsLink creation in useMemo with guard to prevent 'Missing :learnerUsername param' error. The generatePath function was being called unconditionally during render even when the link wouldn't be displayed, causing errors when author was null, undefined, or the 'anonymous' string. The fix ensures generatePath is only called when showUserNameAsLink is true, which validates that author is a valid username.
cc79730 to
ea85320
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #821 +/- ##
=======================================
Coverage 94.56% 94.56%
=======================================
Files 164 164
Lines 3622 3625 +3
Branches 996 992 -4
=======================================
+ Hits 3425 3428 +3
Misses 183 183
Partials 14 14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I went ahead and merged this as it fits with the existing patterns used in this component. I do think in this scenario we could have avoided the unconditionally running issue by moving const AuthorLabel = ({...}) => {
[...]
const learnerPostsLink = (...);
[...]
return ([...]);
}we could have done const LearnerPostsLink = (...);
const AuthorLabel = ({...}) => {
[...]
return ([...]);
}In that case we would have been able to avoid adding the if (!showUserNameAsLink) {
return null;
}check. |
|
@blarghmatey will you be opening up a PR against Ulmo for this fix? |
Description
This PR fixes the 'Missing :learnerUsername param' error that occurs in the AuthorLabel component when the author field is null, undefined, or the 'anonymous' string.
Problem
The
learnerPostsLinkcomponent was being created unconditionally during render, which meantgeneratePath()was called with an invalidauthorvalue even when the link wasn't going to be displayed. This caused the router to throw an error.Solution
Wrapped the
learnerPostsLinkcreation in auseMemohook that:showUserNameAsLinkbefore callinggeneratePath()nullif the link shouldn't be shownTesting
generatePathis only called whenauthoris a valid username and all other conditions (linkToProfile, not anonymous, not in-context sidebar) are met