From 80b827982b17eb276091fabdb5f663858a0a7893 Mon Sep 17 00:00:00 2001 From: Zameel Hassan <43750093+zameel7@users.noreply.github.com> Date: Sat, 1 Feb 2025 14:51:00 +0530 Subject: [PATCH] fix: add null check for post objects in usePostList hook 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 ef434baa2..c31ac9d7b 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); } });