From b3f8e0a56c209b3349bbc3b00daacddd1125bca4 Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 22 Jun 2026 18:24:47 -0600 Subject: [PATCH] Fix iOS offline: NetworkFirst networkTimeoutSeconds + skipWaiting On iOS, offline network requests hang instead of failing fast (navigator.onLine even stays true), so the inventory NetworkFirst route waited forever on the hung network attempt and never fell back to the cache -> infinite spinner offline. Desktop browsers fail the fetch fast, which is why they worked. - networkTimeoutSeconds: 3 on the inventory route, so it serves the cached copy after a few seconds when the network hangs. - self.skipWaiting() so worker updates activate immediately (reach installed PWAs, incl. iOS home-screen apps, without a reinstall). Confirmed on-device via Web Inspector: the home-screen app had the worker active, controlling, and the inventory cached, but fetch('/api/inventory') hung (pending) offline while navigator.onLine reported true. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/src/service-worker.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/service-worker.js b/app/src/service-worker.js index 6f5dac24..7832db16 100644 --- a/app/src/service-worker.js +++ b/app/src/service-worker.js @@ -15,6 +15,9 @@ import {registerRoute} from 'workbox-routing'; import {NetworkFirst, NetworkOnly} from 'workbox-strategies'; import {CacheableResponsePlugin} from 'workbox-cacheable-response'; +// Activate a new worker immediately so fixes/updates reach installed PWAs (incl. iOS home-screen apps) without a +// reinstall, then take control of open clients. +self.skipWaiting(); clientsClaim(); // Precache the shell/JS/CSS emitted by the webpack build. This is what lets the Calculators work offline. @@ -50,6 +53,10 @@ registerRoute( ), new NetworkFirst({ cacheName: 'wrolpi-inventory', + // iOS does not fail offline fetches fast - they hang. Without a timeout, NetworkFirst would wait forever + // on the (hung) network attempt and never fall back to the cache, leaving the page spinning offline. Give + // the network a few seconds, then serve the cached copy. + networkTimeoutSeconds: 3, plugins: [new CacheableResponsePlugin({statuses: [200]})], }) );