fix: prevent empty array id.in filter in single record picker (#18995)

## Summary

- Fixes intermittent `INVALID_QUERY_INPUT` errors (152 occurrences / 2
users in Sentry) caused by the single record picker sending `{ id: { in:
[] } }` to the Search query when no records are selected
- The `skip` guard is logically correct but Apollo Client v4 can briefly
fire queries during React 18 render transitions before processing the
skip flag
- Makes `selectedIdsFilter` conditional on `hasSelectedIds`, so
variables contain a safe empty filter `{}` regardless of skip behavior —
matching the existing defensive pattern used by the third query's
`notFilter`

## Test plan

- [ ] Open a relation field picker (e.g., Person on an Opportunity) with
no existing value — search should load without errors
- [ ] Open a relation field picker with an existing value — selected
record should appear and search should work
- [ ] Clear a selected relation and reopen the picker — no console
errors


Made with [Cursor](https://cursor.com)
This commit is contained in:
Félix Malfait
2026-03-26 11:17:59 +01:00
committed by GitHub
parent b732b2efd4
commit c28e637ea7
@@ -34,13 +34,16 @@ export const useSingleRecordPickerPerformSearch = ({
const { objectMetadataItems } = useObjectMetadataItems();
const selectedIdsFilter = { id: { in: selectedIds } };
const hasSelectedIds = selectedIds.length > 0;
const selectedIdsFilter = hasSelectedIds
? { id: { in: selectedIds } }
: undefined;
const { loading: selectedRecordsLoading, searchRecords: selectedRecords } =
useObjectRecordSearchRecords({
objectNameSingulars,
filter: selectedIdsFilter,
skip: !selectedIds.length,
skip: !hasSelectedIds,
searchInput: '',
});
@@ -50,7 +53,7 @@ export const useSingleRecordPickerPerformSearch = ({
} = useObjectRecordSearchRecords({
objectNameSingulars,
filter: selectedIdsFilter,
skip: !selectedIds.length,
skip: !hasSelectedIds,
searchInput: searchFilter,
});