Skip to content

Commit e9d2490

Browse files
fix: clear the mail draft error and ignore stale loads (#99)
The MailScreen drafts effect never cleared its error, so a banner from a past failure stayed after a later load succeeded. It also had no active guard, so a slow response could overwrite newer drafts. Clear the error before loading and ignore responses from an unmounted or superseded effect, matching the other data loaders in the file. Co-authored-by: Jerel Velarde <85066839+jerelvelarde@users.noreply.github.com>
1 parent 73a7149 commit e9d2490

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎apps/mobile/src/screens.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,19 @@ export function MailScreen() {
453453
const [drafts, setDrafts] = useState<(EmailDraft & { id: string; createdAt: string })[]>([]);
454454
const [error, setError] = useState("");
455455
useEffect(() => {
456+
let active = true;
457+
setError("");
456458
void api
457459
.request<(EmailDraft & { id: string; createdAt: string })[]>("/api/drafts")
458-
.then(setDrafts)
459-
.catch((e) => setError(e instanceof Error ? e.message : String(e)));
460+
.then((next) => {
461+
if (active) setDrafts(next);
462+
})
463+
.catch((e) => {
464+
if (active) setError(e instanceof Error ? e.message : String(e));
465+
});
466+
return () => {
467+
active = false;
468+
};
460469
}, [api, w]);
461470
const items = w.mail.filter(
462471
(m) =>

0 commit comments

Comments
 (0)