Skip to content

fix: prevent double session creation on main branch#40

Merged
dakl merged 2 commits intomainfrom
double-sessions
Apr 6, 2026
Merged

fix: prevent double session creation on main branch#40
dakl merged 2 commits intomainfrom
double-sessions

Conversation

@dakl
Copy link
Copy Markdown
Owner

@dakl dakl commented Apr 6, 2026

Summary

  • Pressing Enter in NewSessionDialog with an empty branch name (main branch session) created two sessions instead of one
  • Root cause: onKeyDown={handleKeyDown} was on both the <input> and its wrapping <div>, so Enter fired handleSubmit twice via event bubbling — and the empty-branch path had no loading guard to block the second call
  • Fix: add event.stopPropagation() in handleKeyDown so the event is consumed by whichever element first handles it

What changed

  • NewSessionDialog.tsx — add stopPropagation() for Enter and Escape keys
  • NewSessionDialog.test.tsx — new component test reproducing the double-submit bug
  • vitest.config.ts — extend test glob to include .test.tsx files
  • package.json — add happy-dom and @testing-library/react / @testing-library/user-event dev deps

Testing

  • New failing test added first (red), then fixed (green): calls onConfirm exactly once when Enter is pressed with empty branch name
  • All 255 tests pass

dakl and others added 2 commits April 6, 2026 14:51
Enables .test.tsx files and the happy-dom environment so React
components can be tested without a full browser.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…anch

NewSessionDialog had onKeyDown on both the <input> and its wrapping
<div>. Pressing Enter in the input fired handleSubmit twice via event
bubbling. For the empty-branch (main branch) path there was no loading
guard, so onConfirm — and createSession — ran twice, producing a
duplicate session in the sidebar.

Fix: call event.stopPropagation() in handleKeyDown so the event is
consumed at whichever element first handles it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@dakl dakl merged commit 263c5f7 into main Apr 6, 2026
3 checks passed
@dakl dakl deleted the double-sessions branch April 6, 2026 12:55
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.

1 participant