A Queue That Survives the Phone

Decide what you would build from the brief alone. Everything below it is available, but the exercise stops working if you open it first.

The brief you were given

Build the client side of an offline-capable form app: queue mutations while offline, sync when connectivity returns, and handle the case where the server has changed the same record.

The trap — the wrong fix that looks right

Using navigator.onLine and the online event to trigger the flush, which is the documented API and works perfectly in testing — toggle airplane mode, the queue drains. That flag reflects whether a network interface exists, not whether your server is reachable: a captive portal at a hotel, a VPN that dropped, a DNS failure or an upstream outage all report online. The flush fires, every request fails, and with no backoff the queue retries against an unreachable server on a phone battery. Reachability is only knowable by making a request and looking at the outcome; the flag is a hint that a retry might be worth attempting.