Skip to main content

Posts

Showing posts with the label Next.js 15

Next.js 15 Caching Changes: Fixing Uncached GET Requests and 'no-store' Defaults

  If you recently migrated a production application from Next.js 14 to Next.js 15, you likely noticed a disturbing trend in your observability tools: a massive spike in upstream API requests. In Next.js 14, the framework was aggressively opinionated about caching. It attempted to cache everything by default, leading to the infamous "why is my data stale?" problem. Next.js 15 inverts this model.  By default,  fetch  requests, GET Route Handlers, and client-side navigations are now uncached. While this solves the stale data confusion, it introduces a new risk: unintentional performance degradation and rate-limiting issues because your application is suddenly re-fetching data on every single render. Here is the root cause of the shift and the precise patterns you need to implement to regain control over your cache strategy. The Root Cause: From "Force-Cache" to "No-Store" In Next.js 14, the extended  fetch  API defaulted to  cache: 'force-cache' . If ...

Fixing 'Text Content Did Not Match' and Caching Gotchas in Next.js 15

  Few things break a developer's flow like the console turning red with   Warning: Text content did not match. Server: "10/24/2024" Client: "10/25/2024" . With the release of Next.js 15, we are seeing a resurgence of hydration errors due to stricter React 19 behaviors, coupled with confusion regarding the complete overhaul of fetch caching defaults. This post dissects the mechanics of hydration mismatches caused by non-deterministic rendering and corrects the implementation patterns for data fetching in the Next.js 15 App Router. Part 1: The Hydration Mismatch The Root Cause: Non-Deterministic Rendering React's hydration process expects the initial DOM generated by the browser to be byte-for-byte identical to the HTML returned by the server. When a component renders something non-deterministic—like  new Date() ,  Math.random() , or  window.localStorage —during the initial render pass, the server snapshot differs from the client's first paint. React 19 (w...