@@ -111,14 +111,6 @@ function mergeNewComment (item, newComment) {
111
111
return { ...item , newComments : [ ...existingNewComments , newComment ] }
112
112
}
113
113
114
- // even though we already deduplicated comments during the newComments merge
115
- // refetches, client-side navigation, etc. can cause duplicates to appear
116
- // we'll make sure to deduplicate them here, by id
117
- function dedupeComments ( existing = [ ] , incoming = [ ] ) {
118
- const existingIds = new Set ( existing . map ( c => c . id ) )
119
- return [ ...incoming . filter ( c => ! existingIds . has ( c . id ) ) , ...existing ]
120
- }
121
-
122
114
function getLatestCommentCreatedAt ( comments , latest ) {
123
115
if ( comments . length === 0 ) return latest
124
116
@@ -151,9 +143,13 @@ export function ShowNewComments ({ newComments = [], itemId, topLevel = false, s
151
143
return fragment || c
152
144
} )
153
145
146
+ // deduplicate the fresh new comments with the existing comments
147
+ const dedupedComments = dedupeComments ( data . comments . comments , freshNewComments )
148
+
154
149
return {
155
150
...data ,
156
- comments : { ...data . comments , comments : dedupeComments ( data . comments . comments , freshNewComments ) } ,
151
+ comments : { ...data . comments , comments : dedupedComments } ,
152
+ ncomments : data . ncomments + ( dedupedComments . length || 0 ) ,
157
153
newComments : [ ]
158
154
}
159
155
}
@@ -170,8 +166,16 @@ export function ShowNewComments ({ newComments = [], itemId, topLevel = false, s
170
166
onClick = { showNewComments }
171
167
className = { `${ topLevel && `d-block fw-bold ${ styles . comment } pb-2` } d-flex align-items-center gap-2 px-3 pointer` }
172
168
>
173
- { newComments . length > 0 ? `${ newComments . length } new comments` : 'new comment' }
169
+ { newComments . length > 1 ? `${ newComments . length } new comments` : 'show new comment' }
174
170
< div className = { styles . newCommentDot } />
175
171
</ div >
176
172
)
177
173
}
174
+
175
+ // even though we already deduplicated comments during the newComments merge,
176
+ // refetches, client-side navigation, etc. can cause duplicates to appear,
177
+ // so we'll make sure to deduplicate them here, by id
178
+ function dedupeComments ( existing = [ ] , incoming = [ ] ) {
179
+ const existingIds = new Set ( existing . map ( c => c . id ) )
180
+ return [ ...incoming . filter ( c => ! existingIds . has ( c . id ) ) , ...existing ]
181
+ }
0 commit comments