How three silent fetch failures caused a Next.js site to cache '0 listings' for a day
A developer running a 3,500-listing directory site built with Next.js discovered that a count of zero was being displayed alongside a full grid of listings for nearly a day. Three separate bugs shared a common root cause: read operations that returned zero on failure, sitting beneath caches that faithfully stored that incorrect value. Next.js's fetch cache does not replay headers like Content-Range, so a cached fetch silently returned null and resolved to zero on every cache hit. When the database recovered, the wrong count persisted because ISR page caches had already baked the zero into rendered pages, including an Open Graph share card that spread the false number across link previews. The fix involved throwing errors inside cached functions rather than returning fallback values, since Next.js's unstable_cache stores nothing on a throw, allowing the next request to fetch fresh data the moment the source recovers.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in