From 2ac3526da95150992324cf59f74aeaa1c7029b74 Mon Sep 17 00:00:00 2001 From: Steven RYDELL Date: Thu, 30 Jul 2026 17:05:12 +0200 Subject: [PATCH] fix: refresh account-scoped lists when switching accounts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switching accounts via the profile dropdown (TopBar) only updates authStore.activeAccountId with no navigation, but DynamicList's fetch effect depended on [viewName, sort, resolved?.list, appliedFilters] — missing activeAccountId, and account resolution only happened through a non-reactive getState() snapshot inside getAccountId(). So views like Mailboxes, Calendars, or Sieve Scripts kept showing the previous account's data until an unrelated viewName change (switching tabs) incidentally re-ran the effect. Reproduced and verified against a live Stalwart instance: a mailbox list stayed on accountId "b" after switching to a group account "d" in the dropdown, and only picked up "d" after navigating away and back. Subscribing to activeAccountId reactively and adding it to the effect's dependencies fixes the switch to apply immediately. Co-Authored-By: Claude Sonnet 5 --- src/components/lists/DynamicList.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/lists/DynamicList.tsx b/src/components/lists/DynamicList.tsx index 0d6f27c..aabea87 100644 --- a/src/components/lists/DynamicList.tsx +++ b/src/components/lists/DynamicList.tsx @@ -418,6 +418,12 @@ export function DynamicList({ viewName }: DynamicListProps) { const viewToSection = useSchemaStore((s) => s.viewToSection); const hasObjectPermission = useAccountStore((s) => s.hasObjectPermission); const edition = useAccountStore((s) => s.edition); + // Reactive, unlike the getAccountId() snapshot read inside fetchData: needed + // so switching accounts from the profile dropdown (a pure store update with + // no navigation) re-triggers the fetch effect below for account-scoped + // views (Mailboxes, Calendars, Sieve Scripts, ...) even when viewName + // itself doesn't change. + const activeAccountId = useAuthStore((s) => s.activeAccountId); const [upsellOpen, setUpsellOpen] = useState(false); const resolved = useMemo(() => { @@ -679,7 +685,7 @@ export function DynamicList({ viewName }: DynamicListProps) { setCurrentAnchor(null); fetchData(null); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [viewName, sort, resolved?.list, appliedFilters]); + }, [viewName, sort, resolved?.list, appliedFilters, activeAccountId]); useEffect(() => { if (!schema || !resolved?.list || items.length === 0) return;