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
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:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user