Skip to content

expandedGroups in useEffect deps causes groups to re-expand on toggle during search #145

Description

@edspencer

Bug

In packages/web/src/client/src/components/all-chats/AllChatsPage.tsx, the auto-expand useEffect includes expandedGroups in its dependency array. Since toggleAllChatsGroup in the Zustand store always creates a new Set instance, every toggle during an active search re-triggers the effect, which calls expandAllChatsGroups() — immediately re-expanding the group the user just collapsed.

Steps to Reproduce

  1. Open All Chats page
  2. Type a search query (groups auto-expand)
  3. Click a group header to collapse it
  4. Observe: the group immediately re-expands

Expected

Users should be able to collapse groups during a search to focus on relevant results.

Root Cause

useEffect(() => {
  if (storeSearchQuery) {
    if (!preSearchExpansionRef.current) {
      preSearchExpansionRef.current = new Set(expandedGroups);
    }
    expandAllChatsGroups();
  } else {
    preSearchExpansionRef.current = null;
  }
}, [storeSearchQuery, expandAllChatsGroups, expandedGroups]); // <-- expandedGroups causes re-runs

expandedGroups is only used once (to capture pre-search state), and that line is guarded by if (!preSearchExpansionRef.current). Removing expandedGroups from the deps array fixes the bug without breaking the capture logic.

File

packages/web/src/client/src/components/all-chats/AllChatsPage.tsx ~line 171-183

Origin

PR #144 CodeRabbit review

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions