Repository navigation
fix(Poll): vote without debounce, relying on stream-chat optimistic votes - #3308
Conversation
β¦otes Remove the 100ms debounce around casting/removing a poll vote. It delayed every vote, merged a quick vote-then-undo into a single toggle, and was never cancelled. stream-chat 9.54.0 applies own votes optimistically and sends vote requests in order, which covers the race the debounce guarded against, so the stream-chat minimum version moves to ^9.54.0. Ignore auto-repeated keydown and the extra clicks of a multi-click, so a held key or a double click toggles the vote once. Refs REACT-1207
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the βοΈ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
Size Change: -1.44 kB (-0.13%) Total Size: 1.09 MB π¦ View Changed
βΉοΈ View Unchanged
|
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-v14 #3308 +/- ##
==============================================
Coverage ? 85.46%
==============================================
Files ? 512
Lines ? 16198
Branches ? 5128
==============================================
Hits ? 13844
Misses ? 2354
Partials ? 0 β View full report in Codecov by Harness. π New features to boost your workflow:
|
Drop the multi-click guard, so every click toggles the vote, including both clicks of a double click, like a native checkbox. Refs REACT-1207
## [14.12.2](v14.12.1...v14.12.2) (2026-10-05) ### Bug Fixes * **Poll:** vote without debounce, relying on stream-chat optimistic votes ([#3308](#3308)) ([35d1152](35d1152))
|
π This PR is included in version 14.12.2 π The release is available on: Your semantic-release bot π¦π |
### Goal Port the stream-chat-react part of #3308 to v15: poll votes are no longer sent through a 100ms debounce, and a held key no longer toggles the vote on every auto-repeat. Linear: [REACT-1207](https://linear.app/stream/issue/REACT-1207/poll-voting-drop-the-100ms-vote-debounce-in-favor-of-stream-chat-954) ### Implementation details - **Debounce removed** from `PollOptionSelector`. `toggleVote` is now a plain `useCallback`, so a vote is sent on click without the 100ms delay. The old `lodash.debounce` instance was recreated on every vote and never cancelled. `lodash.debounce` stays a dependency, as other components still use it. - **Held key ignored.** `onKeyDown` returns early on `event.repeat` (after `preventDefault()`, so a held Space still does not scroll the page). - **stream-chat is unchanged in this PR** (`10.0.0-rc.15`). On v14 the change came with a bump to stream-chat 9.54.0, which applies own votes optimistically and sends vote requests in order. The same optimistic poll votes were ported to v10 in GetStream/stream-chat-js#1904 and released in `stream-chat@10.0.0-rc.19`. Moving master from rc.15 to rc.19 also brings in the breaking changes of rc.16 to rc.18 (26 type errors and 62 failing tests on this branch), which #3306 is already adopting up to rc.18, so the bump is not done here. **Known gap until master is on `stream-chat@10.0.0-rc.19`:** on rc.15 the vote state only changes when the server's event arrives, so a second click before that still reads the previous state and sends another cast instead of a removal. The debounce only merged clicks less than 100ms apart, so it covered this partially before. rc.19 fixes this (stream-chat-js #1904); once master is on it, the rapid-click test from #3308 can be ported too. Tests (`PollOptionList.test.tsx`): - A click sends the vote right away (checked synchronously). Fails with the debounce restored. This replaces #3308's rapid-click test, which depends on 9.54's optimistic votes. - A held key: exactly one `castVote`. Fails without the `event.repeat` guard. ### UI Changes None visually. Votes register without the 100ms delay, and a held key toggles the vote once. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Poll votes now register immediately when an option is selected. * Holding Enter or Space no longer repeatedly toggles a vote. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Goal
Poll votes were sent through a 100ms debounce. It delayed every vote and merged a quick vote-then-undo into a single toggle (leaving the vote in place). stream-chat 9.54.0 ships optimistic poll votes, which handle the race the debounce was guarding against, so the debounce can go and every click toggles the vote.
Linear: REACT-1207
Implementation details
^9.54.0. Bumped the peer and dev dependency (and the examples). 9.54.0 addsOptimisticPollVotes: own-vote state updates as soon as the user clicks, vote requests are sent one at a time in order, removing a not-yet-confirmed cast uses the server vote id from the cast response, and failed requests are reverted. The debounce removal is only safe on top of this, so the minimum version moves with it. On an older stream-chat, a fast second click would read stale own votes and send a duplicate cast.PollOptionSelector.toggleVoteis now a plainuseCallback. The oldlodash.debounceinstance was recreated on every vote (its deps includeownVotesByOptionId) and never cancelled, so a pending call could fire with stale values, even after unmount.lodash.debouncestays a dependency, as other components still use it.onKeyDownreturns early onevent.repeat(afterpreventDefault(), so a held Space still does not scroll the page). Without it, holding Enter/Space toggles the vote on every auto-repeat.Tests (
PollOptionList.test.tsx):castPollVote, then oneremovePollVotewith the server vote id, andaria-pressedfollows each click right away. This goes through the realPolland its optimistic layer, mocking only the client API calls. It fails with the debounce restored.castVote. It fails without theevent.repeatguard.UI Changes
None visually. Votes now register without the 100ms delay, a quick second click undoes the vote, and a held key toggles it once.