From 04acfdc834e0e574227f93c06959299c268906ae Mon Sep 17 00:00:00 2001 From: nvtoan0201-swe Date: Wed, 30 Sep 2026 11:41:51 +0700 Subject: [PATCH] fix: clear the mail draft error and ignore stale loads 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. --- apps/mobile/src/screens.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/mobile/src/screens.tsx b/apps/mobile/src/screens.tsx index 86ba851d..2e4afca7 100644 --- a/apps/mobile/src/screens.tsx +++ b/apps/mobile/src/screens.tsx @@ -453,10 +453,19 @@ export function MailScreen() { const [drafts, setDrafts] = useState<(EmailDraft & { id: string; createdAt: string })[]>([]); const [error, setError] = useState(""); useEffect(() => { + let active = true; + setError(""); void api .request<(EmailDraft & { id: string; createdAt: string })[]>("/api/drafts") - .then(setDrafts) - .catch((e) => setError(e instanceof Error ? e.message : String(e))); + .then((next) => { + if (active) setDrafts(next); + }) + .catch((e) => { + if (active) setError(e instanceof Error ? e.message : String(e)); + }); + return () => { + active = false; + }; }, [api, w]); const items = w.mail.filter( (m) =>