// The browser's localStorage copy of the state is only a cache: the server's SQLite state is the // truth and every page load hydrates from it. A big installation (results, training ledger, logo) // outgrows the ~5 MB quota, and setItem then throws - which used to abort whatever called // saveState(), e.g. connecting the decoder. A cache that can't be written is dropped instead // (the page then starts from the server like a fresh browser); a cut-down copy is never kept, // since a partial state could be synced back over the server's. export function writeLocalCache(storage, key, value) { try { storage.setItem(key, JSON.stringify(value)); return { ok: true }; } catch (error) { try { storage.removeItem(key); } catch {} return { ok: false, error }; } }