From ea85320dfef3511d1d469a13f2a027647ffcb5a5 Mon Sep 17 00:00:00 2001 From: Tobias Macey Date: Thu, 30 Oct 2025 15:23:49 -0400 Subject: [PATCH] fix: prevent generatePath error when author is invalid in AuthorLabel 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 d97120d77..5e424680e 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 ? (