Skip to content

Commit 4d902b8

Browse files
committed
fix(web): reset stale sidebar search selection
1 parent 12d51cc commit 4d902b8

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎apps/web/src/components/SidebarV2.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,19 +1487,20 @@ export default function SidebarV2() {
14871487
() => searchSidebarThreadsByTitle(searchableThreads, threadSearchQuery),
14881488
[searchableThreads, threadSearchQuery],
14891489
);
1490+
const threadSearchResultOrderKey = threadSearchResults
1491+
.map((thread) => scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)))
1492+
.join("\0");
14901493

14911494
useEffect(() => {
1492-
setActiveSearchResultIndex((index) =>
1493-
Math.min(index, Math.max(0, threadSearchResults.length - 1)),
1494-
);
1495-
}, [threadSearchResults.length]);
1495+
setActiveSearchResultIndex(0);
1496+
}, [threadSearchResultOrderKey]);
14961497

14971498
useEffect(() => {
14981499
if (!isSearchingThreads) return;
14991500
document
15001501
.getElementById(`sidebar-thread-search-result-${activeSearchResultIndex}`)
15011502
?.scrollIntoView({ block: "nearest" });
1502-
}, [activeSearchResultIndex, isSearchingThreads, threadSearchResults.length]);
1503+
}, [activeSearchResultIndex, isSearchingThreads, threadSearchResultOrderKey]);
15031504

15041505
// Arm a timeout for the earliest upcoming wake so the shelf empties the
15051506
// moment a snooze expires instead of on the next minute tick. Sorted

0 commit comments

Comments
 (0)