Skip to content

Commit 7080754

Browse files
fix: broken poll vote casting with react compiler (#3308)
## 🎯 Goal This PR fixes an issue of poll votes not being casted correctly while using `React` compiler. This is because the compiler itself optimizes away truthy objects within actual `JSX`/`TSX` differently. Whenever using object accessors directly within a `JSX`/`TSX` closure, the data flow of the compiled code gets confused due to the inability to determine the truthfulness of the expression (and so it defaults to the `falsy` branch). The other way around works because then the object clearly falls into the `falsy` branch (i.e `undefined` or `null`). This is noticeable as it does not particularly break the actual state (vote toggline works for example), however the optimized closure of immutable styles/conditionally rendered styles does not work on the UI. ## 🛠 Implementation details <!-- Provide a description of the implementation --> ## 🎨 UI Changes <!-- Add relevant screenshots --> <details> <summary>iOS</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> <details> <summary>Android</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> ## 🧪 Testing <!-- Explain how this change can be tested (or why it can't be tested) --> ## ☑️ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [ ] PR targets the `develop` branch - [ ] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android Co-authored-by: Khushal Agarwal <[email protected]>
1 parent c41a802 commit 7080754

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

package/src/components/Poll/components/PollOption.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,24 @@ export const VoteButton = ({ onPress, option }: PollVoteButtonProps) => {
181181
toggleVote();
182182
}, [message, onPress, poll, toggleVote]);
183183

184+
const hasVote = !!ownVotesByOptionId[option.id];
185+
184186
return ownCapabilities.castPollVote && !isClosed ? (
185187
<Pressable
186188
onPress={onPressHandler}
187189
style={({ pressed }) => [
188190
{ opacity: pressed ? 0.5 : 1 },
189191
styles.voteContainer,
190192
{
191-
backgroundColor: ownVotesByOptionId[option.id]
192-
? voteButtonActive || accent_dark_blue
193-
: 'transparent',
194-
borderColor: ownVotesByOptionId[option.id]
193+
backgroundColor: hasVote ? voteButtonActive || accent_dark_blue : 'transparent',
194+
borderColor: hasVote
195195
? voteButtonActive || accent_dark_blue
196196
: voteButtonInactive || disabled,
197197
},
198198
voteButtonContainer,
199199
]}
200200
>
201-
{ownVotesByOptionId[option.id] ? <Check height={15} pathFill='white' width={20} /> : null}
201+
{hasVote ? <Check height={15} pathFill='white' width={20} /> : null}
202202
</Pressable>
203203
) : null;
204204
};

0 commit comments

Comments
 (0)