fix: retry mailbox fetch on first login to handle lazy provisioning #217

This commit is contained in:
Linus Rath
2026-04-22 22:45:49 +02:00
parent 6503482b55
commit dd1f3e11e6
+19 -1
View File
@@ -500,7 +500,10 @@ export default function Home() {
// Load mailboxes and emails when authenticated (only if not already loaded) // Load mailboxes and emails when authenticated (only if not already loaded)
useEffect(() => { useEffect(() => {
if (isAuthenticated && client && mailboxes.length === 0) { if (isAuthenticated && client && mailboxes.length === 0) {
const loadData = async () => { let retryTimer: ReturnType<typeof setTimeout> | null = null;
let cancelled = false;
const loadData = async (attempt = 1) => {
try { try {
// First fetch mailboxes and quota (inbox will be auto-selected in fetchMailboxes) // First fetch mailboxes and quota (inbox will be auto-selected in fetchMailboxes)
await Promise.all([ await Promise.all([
@@ -512,6 +515,15 @@ export default function Home() {
const state = useEmailStore.getState(); const state = useEmailStore.getState();
const selectedMailboxId = state.selectedMailbox; const selectedMailboxId = state.selectedMailbox;
// On first login the server may still be provisioning mailboxes.
// Retry a few times with back-off before giving up.
if (state.mailboxes.length === 0 && attempt <= 5 && !cancelled) {
const delay = Math.min(1000 * attempt, 5000);
debug.log('jmap', `[Mailbox] No mailboxes returned (attempt ${attempt}), retrying in ${delay}ms`);
retryTimer = setTimeout(() => loadData(attempt + 1), delay);
return;
}
// Fetch emails for the selected mailbox // Fetch emails for the selected mailbox
if (selectedMailboxId) { if (selectedMailboxId) {
await fetchEmails(client, selectedMailboxId); await fetchEmails(client, selectedMailboxId);
@@ -545,6 +557,12 @@ export default function Home() {
} }
}; };
loadData(); loadData();
return () => {
cancelled = true;
if (retryTimer) clearTimeout(retryTimer);
client.closePushNotifications();
};
} }
// Cleanup push notifications on unmount // Cleanup push notifications on unmount