From e09826d1d1919430442d765509169f53f0b6190f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 17 Apr 2024 22:39:32 -0400 Subject: [PATCH] fix: Race condition where inline comments could be removed, closes #6580 --- app/components/Editor.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/components/Editor.tsx b/app/components/Editor.tsx index 37eb53914..c9f56f51d 100644 --- a/app/components/Editor.tsx +++ b/app/components/Editor.tsx @@ -218,8 +218,8 @@ function Editor(props: Props, ref: React.RefObject | null) { }, [localRef, onHeadingsChange]); const updateComments = React.useCallback(() => { - if (onCreateCommentMark && onDeleteCommentMark) { - const commentMarks = localRef.current?.getComments(); + if (onCreateCommentMark && onDeleteCommentMark && localRef.current) { + const commentMarks = localRef.current.getComments(); const commentIds = comments.orderedData.map((c) => c.id); const commentMarkIds = commentMarks?.map((c) => c.id); const newCommentIds = difference( @@ -229,7 +229,7 @@ function Editor(props: Props, ref: React.RefObject | null) { ); newCommentIds.forEach((commentId) => { - const mark = commentMarks?.find((c) => c.id === commentId); + const mark = commentMarks.find((c) => c.id === commentId); if (mark) { onCreateCommentMark(mark.id, mark.userId); }