Skip to content

Commit b422031

Browse files
authored
[Content] Prevent UI jank when creating or posting reply to a comment (#3294)
[Content---nar-test-2---Zesty-io---zesty-pw---Manager (2).webm](https://github.com/user-attachments/assets/962dd828-6d9f-4aee-8a5b-0ca75aaf83a1)
1 parent e609e0e commit b422031

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Diff for: src/shell/components/Comment/CommentItem.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type CommentItemProps = {
5555
withResolveButton?: boolean;
5656
withReopenButton?: boolean;
5757
onParentCommentDeleted: () => void;
58+
commentCount: number;
5859
};
5960
export const CommentItem = ({
6061
commentZUID,
@@ -65,6 +66,7 @@ export const CommentItem = ({
6566
withResolveButton,
6667
withReopenButton,
6768
onParentCommentDeleted,
69+
commentCount,
6870
}: CommentItemProps) => {
6971
const { resourceZUID } = useParams<PathParams>();
7072
const location = useLocation();
@@ -229,6 +231,7 @@ export const CommentItem = ({
229231
onCancel={() => setCommentZUIDtoEdit(null)}
230232
commentResourceZUID={resourceZUID}
231233
parentCommentZUID={parentCommentZUID}
234+
commentCount={commentCount}
232235
/>
233236
) : (
234237
<Typography

Diff for: src/shell/components/Comment/CommentsList.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export const CommentsList = ({
172172
withReopenButton={index === 0 && isResolved}
173173
parentCommentZUID={parentCommentZUID}
174174
onParentCommentDeleted={onClose}
175+
commentCount={commentThread?.length || 0}
175176
/>
176177
{index + 1 < commentThread?.length && (
177178
<Divider sx={{ my: 1.5 }} />
@@ -209,6 +210,7 @@ export const CommentsList = ({
209210
onCancel={onClose}
210211
commentResourceZUID={resourceZUID}
211212
parentCommentZUID={parentCommentZUID}
213+
commentCount={commentThread?.length || 0}
212214
/>
213215
)}
214216
</Paper>

Diff for: src/shell/components/Comment/InputField.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type InputFieldProps = {
2727
parentCommentZUID: string;
2828
isEditMode?: boolean;
2929
editModeValue?: string;
30+
commentCount: number;
3031
};
3132
export const InputField = ({
3233
isFirstComment,
@@ -35,6 +36,7 @@ export const InputField = ({
3536
parentCommentZUID,
3637
isEditMode = false,
3738
editModeValue = "",
39+
commentCount,
3840
}: InputFieldProps) => {
3941
const [
4042
createComment,
@@ -78,6 +80,7 @@ export const InputField = ({
7880
const [initialValue, setInitialValue] = useState(PLACEHOLDER);
7981
const [mentionListAnchorEl, setMentionListAnchorEl] = useState(null);
8082
const [userFilterKeyword, setUserFilterKeyword] = useState("");
83+
const [prevCommentCount, setPrevCommentCount] = useState(commentCount);
8184

8285
const handleSubmit = () => {
8386
if (isFirstComment) {
@@ -164,14 +167,18 @@ export const InputField = ({
164167
}, [inputValue, isEditMode]);
165168

166169
useEffect(() => {
167-
if (isCommentCreated || isReplyCreated) {
170+
if (
171+
(isCommentCreated || isReplyCreated) &&
172+
prevCommentCount !== commentCount
173+
) {
168174
tinymce?.activeEditor.setContent(PLACEHOLDER);
169175
setInputValue("");
170176
updateComments({
171177
[commentResourceZUID]: "",
172178
});
179+
setPrevCommentCount(commentCount);
173180
}
174-
}, [isCommentCreated, isReplyCreated]);
181+
}, [isCommentCreated, isReplyCreated, prevCommentCount, commentCount]);
175182

176183
useEffect(() => {
177184
if (isCommentUpdated || isReplyUpdated) {
@@ -233,6 +240,7 @@ export const InputField = ({
233240
<Editor
234241
id="commentInputField"
235242
initialValue={initialValue}
243+
disabled={isLoading}
236244
init={{
237245
inline: true,
238246

0 commit comments

Comments
 (0)