Skip to content

fix(discussion): drop the frozen sort snapshot, serialise votes per comment - #1343

Closed
NiallJoeMaher wants to merge 1 commit into
developfrom
fix/comment-vote-races
Closed

fix(discussion): drop the frozen sort snapshot, serialise votes per comment#1343
NiallJoeMaher wants to merge 1 commit into
developfrom
fix/comment-vote-races

Conversation

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Follow-up to #1341. A high-effort review of that PR (run after it had already merged) found the score-freezing was both more than the fix needed and wrong on its own terms.

What #1341 got wrong

  • Ordering could contradict the counts next to it. Displayed scores still updated on a refetch (window refocus, posting a comment) while the frozen ordering did not — so a thread could render a 42-point comment sitting below a 3-point one.
  • The escape hatch never fired. The code comment promised "re-pick the sort to get the current ranking", but setSortOrder("top") when already on top is a no-op, React bails out, and the snapshot is never cleared.
  • It silently changed default ordering. The added newest-first tiebreak made the Top tab identical to New on the common all-zero thread; the previous code relied on Array#sort stability to keep the server's order.
  • It removed the in-flight guard without replacing it. Overlapping requests for the same comment could land in either order, leaving the stored vote disagreeing with the UI — and every rapid tap burned a request against the 100-per-5-minutes limit.
  • One failed vote wiped every optimistic vote. voteResetKey was global, so an error remounted all controls and discarded the state of votes on other comments, including ones still in flight.

What this does

Not refetching after a successful vote is the whole fix on its own. The new count lives in VoteControl; discussions is untouched, so nothing re-ranks under the reader. Ordering goes back to b.score - a.score derived from the data on screen, so it can never contradict what is displayed — and the stable-sort behaviour for ties is preserved.

Votes are serialised per comment, newest click replacing any queued one. One request in flight per comment, so writes cannot land out of order.

The resync remount is per comment, so one failure no longer discards other comments' optimistic state. Server messages (rate limiting) now reach the toast instead of a generic string.

Net: 55 insertions, 75 deletions — this is mostly deleting the machinery #1341 added.

Verified locally

  • Vote → order unchanged, count updates.
  • 8 clicks dispatched back-to-back → 2 requests (was 8), and the stored vote + count match the UI exactly (up, upvotes_count = 1).
  • 6 clicks with small gaps → serialised, DB and UI agree.
  • npm run lint, npm run prettier, npm run test:unit, npm run build.

…omment

Follow-up to #1341. Review found the score-freezing in that change was
both more than the fix needed and wrong on its own terms.

Displayed counts still updated on refetch while the frozen ordering did
not, so a thread could render a 42-point comment sitting below a 3-point
one. The documented "re-pick the sort to get the live ranking" escape
hatch never fired, because selecting the already-selected option is a
no-op. And the tiebreak it introduced made Top identical to New on the
common all-zero thread.

Not refetching after a successful vote is the whole fix on its own: the
new count lives in VoteControl, `discussions` is untouched, so nothing
re-ranks under the reader. Ordering goes back to being derived from the
data on screen, so it can never contradict the counts beside it.

Votes are now serialised per comment, newest click replacing any queued
one. #1341 removed the in-flight guard without replacing it, so
overlapping requests could land in either order and leave the stored vote
disagreeing with the UI; eight rapid clicks now collapse to two requests
rather than eight against the rate limit.

The remount that resyncs a failed vote is per comment too, so one failure
no longer discards the optimistic state of votes on other comments or of
one still in flight, and server messages (rate limiting) reach the toast
instead of a generic string.
@NiallJoeMaher
NiallJoeMaher requested a review from a team as a code owner August 12, 2026 07:26
@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
codu Ready Ready Preview Aug 12, 2026 7:28am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@NiallJoeMaher, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f7e8468a-edc0-4610-a6a2-331a12cbdb89

📥 Commits

Reviewing files that changed from the base of the PR and between 33771d3 and f4db106.

📒 Files selected for processing (1)
  • components/Discussion/DiscussionArea.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Uh oh! @vercel[bot], the image you shared is missing helpful alt text. Check #1343 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

@NiallJoeMaher

Copy link
Copy Markdown
Contributor Author

Superseded by #1344, which consolidates this with #1342 and adds the email-origin fix.

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.

1 participant