fix: refresh account-scoped lists when switching accounts

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 <noreply@anthropic.com>
This commit is contained in:
Steven RYDELL
2026-07-30 17:05:12 +02:00
co-authored by Claude Sonnet 5
parent 3dda6d1527
commit 2ac3526da9
+7 -1
View File
@@ -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;