Skip to content

Comments

Fix race condition in group join: move state update after database operations#5

Draft
Copilot wants to merge 2 commits intocreate-groupfrom
copilot/sub-pr-1-yet-again
Draft

Fix race condition in group join: move state update after database operations#5
Copilot wants to merge 2 commits intocreate-groupfrom
copilot/sub-pr-1-yet-again

Conversation

Copy link

Copilot AI commented Nov 15, 2025

State was updated before database operations completed. If member addition failed, users would see the map view for a group they never successfully joined.

Changes:

  • Moved setCurrentGroup() and setCurrentGroupName() to execute only after all database operations succeed
  • Consolidated error handling into single try-catch around all database operations
  • Added user-facing error message on join failure

Before:

const code = groupCode.toUpperCase();
setCurrentGroup(code);  // State updated immediately
// ... fetch metadata ...
await database.ref(`groups/${code}/members/${user.uid}`).set({...});  // Could fail

After:

const code = groupCode.toUpperCase();
try {
    // ... fetch metadata ...
    await database.ref(`groups/${code}/members/${user.uid}`).set({...});
    setCurrentGroup(code);  // State updated only on success
    setCurrentGroupName(groupName);
} catch (e) {
    alert('Failed to join group. Please try again.');
}

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: kelliherm <63371331+kelliherm@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on 'Added ability to create a group' PR Fix race condition in group join: move state update after database operations Nov 15, 2025
Copilot AI requested a review from kelliherm November 15, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants