From f0dacf754b4c002c1c797825ae33943eac06aa45 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 7 May 2024 21:27:11 -0500 Subject: [PATCH] Prevent edit timer jump --- components/reply.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/reply.js b/components/reply.js index 85d77ce32a..4d8cd92649 100644 --- a/components/reply.js +++ b/components/reply.js @@ -49,6 +49,11 @@ const cacheUpdateAncestors = (cache, ancestors) => { const cacheRemovePendingComment = (cache, parentId) => { const id = PENDING_COMMENT_ID + const pendingComment = cache.readFragment({ + id: `Item:${id}`, + fragment: COMMENTS, + fragmentName: 'CommentsRecursive' + }) cache.modify({ id: `Item:${parentId}`, fields: { @@ -57,6 +62,7 @@ const cacheRemovePendingComment = (cache, parentId) => { } } }) + return pendingComment } const cacheRevertAncestorUpdate = (cache, ancestors) => { @@ -167,8 +173,10 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children } }`, { update (cache, { data: { upsertComment } }) { - cacheRemovePendingComment(cache, parentId) - cacheAddComment(cache, parentId, upsertComment) + // prevent edit timer jump + const pendingComment = cacheRemovePendingComment(cache, parentId) + const comment = { ...upsertComment, createdAt: pendingComment.createdAt } + cacheAddComment(cache, parentId, comment) const ancestors = item.path.split('.') // XXX cache update already applied