Skip to content

Reset per-post social state on post switch to prevent leakage of likes and comments#65

Open
cto-new[bot] wants to merge 1 commit intomainfrom
fix-separate-comments-likes-per-post-visibility
Open

Reset per-post social state on post switch to prevent leakage of likes and comments#65
cto-new[bot] wants to merge 1 commit intomainfrom
fix-separate-comments-likes-per-post-visibility

Conversation

@cto-new
Copy link
Copy Markdown
Contributor

@cto-new cto-new bot commented Jan 4, 2026

Summary

This change fixes an issue where likes and comments were visible across posts due to shared social state. Switching posts now shows correct, per-post interactions.

Details

  • Reset social state (likesCount, isLiked, comments, newComment, isSubmittingComment) when the selected post changes.
  • Implemented in the post list and detail flows to ensure per-post isolation of social data.
  • Improves correctness of UI by preventing leakage of likes/comments across posts.
  • No breaking changes; no migrations required.

Open with Devin

@cto-new cto-new bot requested a review from Ardelyo as a code owner January 4, 2026 08:42
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
ourcreativity Ready Ready Preview, Comment Jan 4, 2026 8:43am

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View issues and 3 additional flags in Devin Review.

Open in Devin Review

Comment thread pages/Karya.tsx
Comment on lines +361 to +368
useEffect(() => {
// Reset to empty states when selectedId changes
setLikesCount(0);
setIsLiked(false);
setComments([]);
setNewComment('');
setIsSubmittingComment(false);
}, [selectedId]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Race condition: Reset effect overwrites cached social data when switching posts

In both Karya.tsx and Profile.tsx, the newly added useEffect that resets social states (likes, comments, etc.) when selectedId changes runs AFTER the effect that syncs from socialData. This causes a race condition:

  1. When selectedId changes to a previously viewed post, React Query immediately returns cached socialData
  2. The socialData sync effect (lines 347-353 in Karya.tsx, 243-249 in Profile.tsx) runs and sets the correct values
  3. The reset effect (lines 361-368 in Karya.tsx, 252-259 in Profile.tsx) runs afterward and overwrites the correct data with zeros/empty arrays

This results in:

  • User sees correct cached data briefly, then it resets to 0/empty
  • After refetch completes, data is restored (causing a flicker)
  • If the user interacts (e.g., likes) during this window, they operate on incorrect state

The fix should either:

  1. Move the reset effect BEFORE the sync effect, or
  2. Use a ref to track the previous selectedId and only reset when actually switching, or
  3. Remove the reset effect entirely and rely on React Query's loading state to show a placeholder
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread pages/Profile.tsx
Comment on lines +252 to +259
useEffect(() => {
// Reset to empty states when selectedId changes
setLikesCount(0);
setIsLiked(false);
setComments([]);
setNewComment('');
setIsSubmittingComment(false);
}, [selectedId]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Race condition: Reset effect overwrites cached social data when switching posts

Same issue as in Karya.tsx. The newly added useEffect at lines 252-259 resets social states when selectedId changes, but it runs AFTER the effect at lines 243-249 that syncs from socialData. When switching to a previously viewed post with cached data:

  1. React Query returns cached socialData immediately
  2. The sync effect runs and sets correct values from cache
  3. The reset effect runs and overwrites with zeros/empty

This causes incorrect display of likes count (showing 0 instead of actual count), isLiked state being wrong (showing not liked when user has liked), and comments being cleared.

The fix should reorder the effects or use a different approach to handle the transition state.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants