Skip to content

fix(ui): preserve selected options in hasMany relationship filter while searching#17088

Open
jhjh1214 wants to merge 3 commits into
payloadcms:mainfrom
jhjh1214:fix/relationship-filter-loses-selection-while-searching
Open

fix(ui): preserve selected options in hasMany relationship filter while searching#17088
jhjh1214 wants to merge 3 commits into
payloadcms:mainfrom
jhjh1214:fix/relationship-filter-loses-selection-while-searching

Conversation

@jhjh1214

Copy link
Copy Markdown
Contributor

Fixes #17048

What?

Filtering by a hasMany relationship field in the admin where-builder could intermittently drop a previously-selected item after selecting/searching for another one.

Why?

findOptionsByValue()'s multi-value branch returned undefined for any selected value not currently present in the loaded options list. This happens any time the user types into the search box: handleInputChange synchronously clears options via the reducer's CLEAR action, before the async re-fetch (which patches missing selections back in) completes. During that window, ReactSelect is a fully-controlled component, so any interaction with it (selecting/removing another chip) reports back a selection containing that hole, and onChange propagates it upward, genuinely losing the item from the filter's value, not just visually.

The single-value branch right below it already guards against this exact case with a || value fallback; the multi-value branch was missing the equivalent per-entry protection.

How?

Fall back to a placeholder { label, value, relationTo } option instead of undefined when no match is found, so the array fed into ReactSelect never has holes. Once the real document loads via the existing patch effect, the next render naturally replaces the placeholder with the properly-labeled option.

Tests

Added a regression e2e test that selects two items, then types a search query and uses page.route() to hold back the reload request, deterministically asserting both previously-selected chips remain visible during that window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filtering by relationship entries sometimes removes the selected item

1 participant