From a4826ae62de72613c587b83f6a70cc417ca9cc36 Mon Sep 17 00:00:00 2001 From: Tobias Macey Date: Thu, 13 Nov 2025 16:08:51 -0500 Subject: [PATCH] fix: prevent generatePath error when author is invalid in AuthorLabel (#821) 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. --- src/discussions/common/AuthorLabel.jsx | 27 +++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/discussions/common/AuthorLabel.jsx b/src/discussions/common/AuthorLabel.jsx index d97120d7..5e424680 100644 --- a/src/discussions/common/AuthorLabel.jsx +++ b/src/discussions/common/AuthorLabel.jsx @@ -101,17 +101,22 @@ const AuthorLabel = ({ ), [author, authorLabelMessage, authorToolTip, icon, isRetiredUser, postCreatedAt, showTextPrimary, alert]); - const learnerPostsLink = ( - - {!alert && authorName} - - ); + const learnerPostsLink = useMemo(() => { + if (!showUserNameAsLink) { + return null; + } + return ( + + {!alert && authorName} + + ); + }, [showUserNameAsLink, author, courseId, alert, authorName]); return showUserNameAsLink ? (