Skip to content

Comments

fix(GameView): add null check for queen lookup in validFaceCardTargetIds#1337

Closed
seriouslysean wants to merge 1 commit intomainfrom
fix/null-check-queen-find
Closed

fix(GameView): add null check for queen lookup in validFaceCardTargetIds#1337
seriouslysean wants to merge 1 commit intomainfrom
fix/null-check-queen-find

Conversation

@seriouslysean
Copy link
Collaborator

@seriouslysean seriouslysean commented Feb 10, 2026

Found during a code audit.validFaceCardTargetIds() calls .find() for a queen and immediately accesses .id without 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

  • N/A (found during code audit)

Please check the following

  • Do the tests still pass?
  • Is the code formatted properly?

Please describe additional details for testing this change

  1. npm run test:unit
  2. Play a game where the opponent has one queen and target it with a 2 or 9 — should work the same

Copilot AI review requested due to automatic review settings February 10, 2026 03:30
@seriouslysean seriouslysean added bug Something isn't working version-patch An update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1) labels Feb 10, 2026
@seriouslysean seriouslysean self-assigned this Feb 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +643 to +646
case 1: {
const queen = this.gameStore.opponent.faceCards.find((card) => card.rank === 12);
return queen ? [ queen.id ] : [];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@itsalaidbacklife
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working version-patch An update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants