fix(vote): éviter les double-votes sur useVote/VoteProvider (chargement + double-clic) - #270
Closed
hboisgibault wants to merge 1 commit into
Closed
fix(vote): éviter les double-votes sur useVote/VoteProvider (chargement + double-clic)#270hboisgibault wants to merge 1 commit into
hboisgibault wants to merge 1 commit into
Conversation
- VoteProvider now exposes the registered voteableIds and a votesLoading flag, so consumers know when the user's existing votes have been loaded. - useVote no longer creates a vote while the VoteProvider is still loading the existing votes of a registered voteable (prevents the duplicate create that would raise PG::UniqueViolation on the API). - A synchronous ref lock (on top of the existing voteDisabled state) blocks rapid double-clicks from issuing concurrent create/update/delete. - UpDownVoteBox, VoteButton and SuggestionVoteBox disable their buttons while the vote state is not ready yet.
hboisgibault
force-pushed
the
fix/usevote-double-vote
branch
from
August 17, 2026 11:59
9b3f47a to
3781170
Compare
Collaborator
Author
|
PR remplacé par une version simplifiée et plus élégante : voir #271 (verrou synchrone minimal anti envoi multiple). La protection définitive contre les doublons restants est portée côté API (Logora/LogoraAPI#779, création idempotente). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objectif
Éviter les double-votes côté interface sur les votes d'arguments/messages (
useVote:UpDownVoteBox,VoteButton,SuggestionVoteBox, voteablesMessage,Proposal,DebateSuggestion), qui provoquent côté API unePG::UniqueViolation→ HTTP 500 (LogoraAPI #763).Cause racine (côté interface)
Les composants basés sur
useVotedécident entrePOST(create),PATCH(update) etDELETEselon un étatactiveVotechargé de façon asynchrone via leVoteProvider(listeGET /votes). Tant que cette liste n'est pas arrivée,activeVotevautfalse: un clic part donc encreate, même si l'utilisateur a déjà voté → doublon côté serveur.Correctifs
VoteProviderexpose désormais lesvoteableIdsenregistrés et un indicateurvotesLoading.useVoterefuse de créer un vote tant que leVoteProvidern'a pas fini de charger les votes existants du voteable enregistré (isVoteReady). Les composants ne sont donc plus « aveugles » pendant le chargement.useRef, en complément de l'étatvoteDisabledexistant) : pendant qu'uncreate/update/deleteest en vol, tout nouveau clic est ignoré (garde posée de façon synchrone, pas seulement viasetState).UpDownVoteBox,VoteButton,SuggestionVoteBoxdésactivent leur bouton tant que l'état du vote n'est pas prêt.Tests
useVote > should not create a vote while the existing votes are still loading: aucunPOSTpendant le chargement, puisPOSTautorisé une fois chargé.useVote > should not create multiple votes on rapid clicks: deux clics rapides ne produisent qu'un seulPOST.VoteButton > should be disabled while the vote state is still loading.Note
Correctif côté interface uniquement. Une idempotence côté API (
VotesController#create) reste recommandée en défense en profondeur (voir issue LogoraAPI #763).Ce PR a été créé par un agent IA (OpenHands) pour le compte de l'utilisateur.