Skip to content

fix: Show "Search for X" option when reopening UserSearch with text#262

Open
Amund211 wants to merge 2 commits into
mainfrom
fix-user-search-freetext-on-reopen
Open

fix: Show "Search for X" option when reopening UserSearch with text#262
Amund211 wants to merge 2 commits into
mainfrom
fix-user-search-freetext-on-reopen

Conversation

@Amund211

Copy link
Copy Markdown
Owner

Summary

  • Fixes the player search component dropping the "Search for X" free-text option when the popup is reopened with text already in the input (after a previous selection). Reproducible on /session/$uuid where the component stays mounted across selection.
  • Root cause: MUI's useAutocomplete passes inputValue: '' to filterOptions when inputValueIsSelectedValue && inputPristine (single-select, the input still holds the previously selected option's label, and the popup just reopened). That zeros out the inputValue.trim() ? [...] : [] branch in our filterOptions.
  • Fix: control inputValue ourselves and forward it to filterOptions, bypassing the empty-string trick.
  • Added a UI test on /session/$uuid that reproduces the bug; verified it fails on the parent commit.

Test plan

  • pnpm tsc
  • pnpm lint:check
  • pnpm test:ui:chromium — all 197 tests pass
  • Confirmed new test fails on the commit before the fix

🤖 Generated with Claude Code

Amund211 and others added 2 commits May 16, 2026 19:44
MUI's Autocomplete passes `inputValue: ''` to `filterOptions` when the
popup reopens with the input value matching the previously selected
option's label. That suppressed the free-text "Search for X" entry until
the user typed a character to flip the pristine flag.

Control `inputValue` ourselves and forward it to `filterOptions` so the
free-text option is always shown when there's text in the input.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Asserts that the "Search for X" option appears when the search popup
is reopened after a previous selection has filled the input with that
option's label. Without the fix in the preceding commit, MUI's
empty-string trick passes inputValue: '' to filterOptions on reopen
and suppresses the free-text branch until the user edits the input.

Verified the test fails on HEAD~1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 16, 2026 17:56
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rainbow with  Cloudflare Pages  Cloudflare Pages

Latest commit: 50d030f
Status: ✅  Deploy successful!
Preview URL: https://7bd19cd7.rainbow-ctx.pages.dev
Branch Preview URL: https://fix-user-search-freetext-on.rainbow-ctx.pages.dev

View logs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a MUI Autocomplete edge case where the UserSearch free-text “Search for X” option disappears when reopening the popup while the input still contains the previously selected option’s label (common on /session/$uuid where the component stays mounted across navigation).

Changes:

  • Controls Autocomplete’s inputValue in UserSearch and forwards that value into filterOptions to avoid MUI’s reopen-time empty-string inputValue behavior.
  • Adds a UI regression test on the session detail route to ensure the free-text option is still shown after reopening with previously selected text.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/components/UserSearch.tsx Controls inputValue and ensures filterOptions receives the real input text when reopening.
src/routes/session/-uuid.ui.test.tsx Adds a UI test reproducing the reopen regression and asserting the free-text option is present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +304 to 311
<Autocomplete<SearchOption, false, true>
options={uuids.map((uuid) => ({ type: "uuid" as const, uuid }))}
fullWidth
size={size}
// TODO: Clear the input when the user selects an option
blurOnSelect
selectOnFocus
autoHighlight
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