Offline UX: network failures show quiet 'offline, n queued' not errors; auto-sync on connectivity regain + 45s heartbeat
All checks were successful
Build & Release APK / build (push) Successful in 2m10s

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-07 23:50:34 -07:00
parent 64967c19a0
commit 6ccd417f2a
5 changed files with 43 additions and 5 deletions

View File

@@ -18,6 +18,8 @@ export interface State {
hydrated: boolean;
syncing: boolean;
pending: number;
/** True when the last sync failed for network reasons — expected offline. */
offline: boolean;
syncError: string | null;
}
@@ -34,6 +36,7 @@ let state: State = {
hydrated: false,
syncing: false,
pending: 0,
offline: false,
syncError: null,
};
let queue: Op[] = [];
@@ -193,9 +196,13 @@ export async function sync() {
setState({});
}
await pull();
setState({ syncError: null });
setState({ syncError: null, offline: false });
} catch (e) {
setState({ syncError: e instanceof Error ? e.message : String(e) });
const msg = e instanceof Error ? e.message : String(e);
// fetch() network failures (airplane mode, no wifi, DNS) are the expected
// offline case, not an error — the queue simply waits for connectivity.
const isNetwork = e instanceof TypeError || /network request failed|unable to resolve|fetch failed|timeout/i.test(msg);
setState(isNetwork ? { offline: true, syncError: null } : { syncError: msg });
} finally {
syncRunning = false;
setState({ syncing: false });