File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -171,13 +171,20 @@ export default function PostPage() {
171171
172172 // Filter out optimistic updates and merge with real data
173173 setComments ( prevComments => {
174- const tempComments = prevComments . filter ( c => c . id . startsWith ( 'temp-' ) ) ;
175174 const realComments = commentsData ;
176175
177- // Detect new comments for animation
178- const prevCommentIds = new Set ( prevComments . map ( c => c . id ) ) ;
176+ // Get all real comment contents to match against optimistic ones
177+ const realCommentContents = new Set ( realComments . map ( c => c . content . trim ( ) ) ) ;
178+
179+ // Keep only temp comments that don't have a matching real comment yet
180+ const tempComments = prevComments . filter ( c =>
181+ c . id . startsWith ( 'temp-' ) && ! realCommentContents . has ( c . content . trim ( ) )
182+ ) ;
183+
184+ // Detect new comments for animation (only real comments that weren't in previous state)
185+ const prevRealCommentIds = new Set ( prevComments . filter ( c => ! c . id . startsWith ( 'temp-' ) ) . map ( c => c . id ) ) ;
179186 const newCommentIds = realComments
180- . filter ( c => ! prevCommentIds . has ( c . id ) && ! c . id . startsWith ( 'temp-' ) )
187+ . filter ( c => ! prevRealCommentIds . has ( c . id ) )
181188 . map ( c => c . id ) ;
182189
183190 if ( newCommentIds . length > 0 ) {
You can’t perform that action at this time.
0 commit comments