Skip to content

fix: prevent option ID collisions in CreateSurvey component#2598

Merged
MarcelMichau merged 2 commits intofeat/frontend-hygienefrom
copilot/sub-pr-2597
Jan 20, 2026
Merged

fix: prevent option ID collisions in CreateSurvey component#2598
MarcelMichau merged 2 commits intofeat/frontend-hygienefrom
copilot/sub-pr-2597

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

The addOption function used Math.max to generate IDs, causing collisions when options were removed then added:

// Before: IDs could collide
id: Math.max(...prev.survey.options.map((o) => o.id), 0) + 1
// Add option #2 → Remove #2 → Add option → ID 2 reused ❌

// After: monotonic counter prevents collisions
const nextOptionIdRef = useRef(2);
// Add option #2 → Remove #2 → Add option → ID 3 assigned ✓

Changes:

  • Replace Math.max calculation with useRef counter that increments independently of removals
  • Reset counter when form is reset to maintain consistent state
  • Add test verifying unique IDs after remove/add sequences

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

Co-authored-by: MarcelMichau <7761114+MarcelMichau@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tests for CreateSurvey, GetSurvey, and MySurveys fix: prevent option ID collisions in CreateSurvey component Jan 20, 2026
Copilot AI requested a review from MarcelMichau January 20, 2026 06:01
@MarcelMichau
Copy link
Owner

@copilot rebase these changes onto the target branch to get the latest changes from the target

Copy link
Contributor Author

Copilot AI commented Jan 20, 2026

@copilot rebase these changes onto the target branch to get the latest changes from the target

I'm unable to perform a rebase operation because:

  1. Force push is not available in this environment (required for rebase)
  2. The target branch for PR feat: add tests for CreateSurvey, GetSurvey, and MySurveys components #2597 is not available in the repository
  3. This is a shallow clone with limited history

Could you either:

  • Perform the rebase locally, or
  • Let me know if there are specific changes from the target branch that need to be incorporated, and I can apply them manually?

@MarcelMichau MarcelMichau marked this pull request as ready for review January 20, 2026 06:13
@MarcelMichau MarcelMichau merged commit 37e27c9 into feat/frontend-hygiene Jan 20, 2026
3 of 5 checks passed
@MarcelMichau MarcelMichau deleted the copilot/sub-pr-2597 branch January 20, 2026 06:14
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