From f04429f6f79a416af5c1e29c4c41c40a2cfdcb52 Mon Sep 17 00:00:00 2001 From: Zameel Hassan <43750093+zameel7@users.noreply.github.com> Date: Mon, 12 May 2025 19:17:17 +0530 Subject: [PATCH] fix: add null check for post objects in usePostList hook (#752) Adds defensive null checks when accessing post properties in the posts forEach loop to prevent potential errors in the MFE discussion sidebar. This addresses the issue reported in #751. --- src/discussions/posts/data/hooks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/discussions/posts/data/hooks.js b/src/discussions/posts/data/hooks.js index ef434baa..c31ac9d7 100644 --- a/src/discussions/posts/data/hooks.js +++ b/src/discussions/posts/data/hooks.js @@ -11,9 +11,9 @@ const usePostList = (ids) => { const sortedIds = useMemo(() => { posts.forEach((post) => { - if (post.pinned) { + if (post && post.pinned) { pinnedPostsIds.push(post.id); - } else { + } else if (post) { unpinnedPostsIds.push(post.id); } });