From 38dcaa14f79467e359fa41dc7be185ee53b38df8 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sun, 16 Aug 2026 22:54:25 +0200 Subject: [PATCH] fix(forward): keep search results from being dropped mid-typing useAsyncSearch clears its result whenever the list identity changes. In the room picker that list is derived from pickRoom, whose identity churned on every GlobalModalManager render, so any room activity wiped the search and fell back to recent rooms. Key eligibleSet on the room ids instead of the pickRoom object, and make close stable. --- src/app/components/message/modals/GlobalModalManager.tsx | 6 ++++-- src/app/features/navigate/RoomSearch.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/components/message/modals/GlobalModalManager.tsx b/src/app/components/message/modals/GlobalModalManager.tsx index 9fd4b9add..11df2aaad 100644 --- a/src/app/components/message/modals/GlobalModalManager.tsx +++ b/src/app/components/message/modals/GlobalModalManager.tsx @@ -1,3 +1,4 @@ +import { useCallback } from 'react'; import { useAtom } from 'jotai'; import { OverlayBackdrop, OverlayCenter, Box, Modal } from 'folds'; import { Overlay } from '$components/overlay-stack'; @@ -17,9 +18,10 @@ import { MobileOptionsInternal } from './Options'; export function GlobalModalManager() { const [modal, setModal] = useAtom(modalAtom); - const close = () => { + // stable so modals memoizing on it don't rebuild on every room view render + const close = useCallback(() => { setModal(null); - }; + }, [setModal]); // Forward and MobileOptions render their own back handlers via their children. useDismissOnBack( diff --git a/src/app/features/navigate/RoomSearch.tsx b/src/app/features/navigate/RoomSearch.tsx index 66de20dad..2cbde7542 100644 --- a/src/app/features/navigate/RoomSearch.tsx +++ b/src/app/features/navigate/RoomSearch.tsx @@ -158,9 +158,11 @@ export function RoomSearchModal({ const spaces = useSpaces(mx, allRoomsAtom); const directs = useDirects(mx, allRoomsAtom, mDirects); + // keyed on the ids, not on pickRoom, whose callbacks change on every host render + const eligibleRoomIds = pickRoom?.eligibleRoomIds; const eligibleSet = useMemo( - () => (pickRoom ? new Set(pickRoom.eligibleRoomIds) : null), - [pickRoom] + () => (eligibleRoomIds ? new Set(eligibleRoomIds) : null), + [eligibleRoomIds] ); const rawTopActiveRooms = useTopActiveRooms(searchRoomType, rooms, directs, spaces);