Skip to content

fix(competition): keep dialog focus on re-render - #185

Open
kcrmin wants to merge 1 commit into
developfrom
bugfix/dialog-focus-steal
Open

kcrmin wants to merge 1 commit into
developfrom
bugfix/dialog-focus-steal

Conversation

@kcrmin

@kcrmin kcrmin commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

What and why

DialogShell in CompetitionApiWorkspace.tsx ran its open-time effect with [onClose] as a dependency. RoomApiDetail passes () => setJoinOpen(false), a new function on every render, so whenever the leaderboard or "my bots" request resolved while the join dialog was open, the effect cleaned up and re-ran: focus jumped back to the close button and keystrokes landed outside the field the user was typing in.

The same bug explains an intermittent failure in submits room creation schedule and joins with a validation run: when the lobby re-renders while "새 대회" is being typed, focus jumps to "대회 만들기 닫기" and the space key presses it, closing the dialog. A throwaway probe that lands a lobby re-render mid-typing reproduces this on develop and passes on this branch.

The effect now runs once per open. onClose is read through a ref that tracks the latest prop, so Escape still calls the current handler.

Verified

  • New test keeps focus in the join dialog while the room detail re-renders fails on develop (focus is on the close button) and passes with the fix.
  • node --test scripts/test-github-action-pins.mjs scripts/test-real-api-integration-workflow.mjs: 2 passed
  • pnpm typecheck: clean
  • pnpm exec vitest run (Node 24): 58 files, 689 tests passed
  • pnpm build && node scripts/assert-production-bundle.mjs: passed
  • CI=1 pnpm e2e: 26 passed

Checklist

  • Regression test reproduces the bug before the fix
  • Escape, Tab trap and focus restore behave as before
  • No change to other dialogs or public props

Room detail passes an inline onClose, so every parent render re-ran
the open effect and moved focus back to the close button.
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