fix(GameView): add null check for queen lookup in validFaceCardTargetIds#1337
fix(GameView): add null check for queen lookup in validFaceCardTargetIds#1337seriouslysean wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Prevents a runtime crash in GameView when targeting face cards during transiently inconsistent socket-updated game state, by guarding against .find() returning undefined.
Changes:
- Add a null check around the opponent queen lookup in
validFaceCardTargetIds(). - Return an empty list of valid targets when the queen is not yet present in
opponent.faceCards.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case 1: { | ||
| const queen = this.gameStore.opponent.faceCards.find((card) => card.rank === 12); | ||
| return queen ? [ queen.id ] : []; | ||
| } |
There was a problem hiding this comment.
As a sanity check I don't mind this, but I don't think it's actually possible for queen to ever be undefined because this is the switch case on opponentQueenCount === 1 and opponentQueenCount is literally opponent.faceCards.filter(card => card.rank === 12).length so it shouldn't be possible for the queenCount to be 1 but not to find any queens here
|
I think we can close this one, since I can't see how the queenCount could be >=0 and then fail to find a card with rank 12 since they loop through the same ref |
Found during a code audit.
validFaceCardTargetIds()calls.find()for a queen and immediately accesses.idwithout checking if find returned undefined. If game state is briefly inconsistent during a socket update (opponent queen count says 1 but the card hasn't arrived yet), this throws a TypeError.Added a null check so it returns an empty array instead of crashing.
Issue number
Please check the following
Please describe additional details for testing this change
npm run test:unit