Dev.to
8/4/2026

A failed read must throw, not return 0 — how Next.js ISR bakes your fallback into the cache
Short summary
A detailed post-mortem of three caching bugs in a Next.js ISR site where failed database reads returned 0 and got baked into page caches for hours. The core lesson: cached functions must throw on failure, not return a polite default, because unstable_cache and ISR page caches will store the wrong answer. The author also discovered PostgREST row-count headers aren't preserved by fetch cache, and that client-side aggregation over capped responses silently drops data.
- •Failed reads returning 0 get cached by Next.js ISR and persist beyond the outage
- •Fix: throw inside cached functions so unstable_cache stores nothing on error
- •PostgREST caps responses at 1000 rows; aggregate server-side to avoid silent data loss
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



