diff --git a/packages/editor/src/components/collab-sidebar/index.js b/packages/editor/src/components/collab-sidebar/index.js index c53ee9e7e919c..b8010aaea351b 100644 --- a/packages/editor/src/components/collab-sidebar/index.js +++ b/packages/editor/src/components/collab-sidebar/index.js @@ -296,19 +296,23 @@ export default function CollabSidebar() { return { resultComments: [], sortedThreads: [] }; } + const blockCommentIds = getCommentIdsFromBlocks( blocks ); + const blockCommentIdMap = new Map( + blockCommentIds.map( ( item ) => [ item.commentID, item ] ) + ); + const updatedResult = result.map( ( item ) => ( { ...item, reply: [ ...item.reply ].reverse(), + clientId: blockCommentIdMap.get( item.id )?.clientID, } ) ); - const blockCommentIds = getCommentIdsFromBlocks( blocks ); - const threadIdMap = new Map( updatedResult.map( ( thread ) => [ thread.id, thread ] ) ); const sortedComments = blockCommentIds - .map( ( id ) => threadIdMap.get( id ) ) + .map( ( item ) => threadIdMap.get( item.commentID ) ) .filter( ( thread ) => thread !== undefined ); return { resultComments: updatedResult, sortedThreads: sortedComments }; diff --git a/packages/editor/src/components/collab-sidebar/utils.js b/packages/editor/src/components/collab-sidebar/utils.js index 51345392098ff..020ab14790eef 100644 --- a/packages/editor/src/components/collab-sidebar/utils.js +++ b/packages/editor/src/components/collab-sidebar/utils.js @@ -27,7 +27,10 @@ export function getCommentIdsFromBlocks( blocks ) { block.attributes.blockCommentId && ! commentIds.includes( block.attributes.blockCommentId ) ) { - commentIds.push( block.attributes.blockCommentId ); + commentIds.push( { + clientID: block.clientId, + commentID: block.attributes.blockCommentId, + } ); } // Recursively check inner blocks