From 51f228b3f87a2499a2a3ab642ae2757d3dc12eaa Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:24:55 +0200 Subject: [PATCH] Fix React duplicate key error with initial users in UserSearch Not really sure how this works exactly. It doesn't seem the user is visually duplicated despite clearly being there twice in data, something react-aria-components does under the hood perhaps? --- app/components/elements/UserSearch.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/components/elements/UserSearch.tsx b/app/components/elements/UserSearch.tsx index 56d7b8d27..045754a10 100644 --- a/app/components/elements/UserSearch.tsx +++ b/app/components/elements/UserSearch.tsx @@ -238,12 +238,16 @@ function useUserSearch( [filterText], ); + const initialUserResult = initialUserFetcher.data?.results.find( + (r): r is UserResult => r.type === "user", + ); + const items = () => { // data fetched for the query user has currently typed if (queryFetcher.data && queryFetcher.data.query === filterText) { - const userResults = queryFetcher.data.results.filter( - (r): r is UserResult => r.type === "user", - ); + const userResults = queryFetcher.data.results + .filter((r): r is UserResult => r.type === "user") + .filter((user) => user.id !== initialUserResult?.id); if (userResults.length === 0) { return [{ id: "NO_RESULTS" as const }]; } @@ -253,10 +257,6 @@ function useUserSearch( return [{ id: "PLACEHOLDER" as const }]; }; - const initialUserResult = initialUserFetcher.data?.results.find( - (r): r is UserResult => r.type === "user", - ); - return { filterText, setFilterText,