Skip to content
Homeβ€Ί JavaScriptβ€Ί Next.js 16: Every New Feature Explained with Code Examples (2026 Guide)

Next.js 16: Every New Feature Explained with Code Examples (2026 Guide)

Where developers are forged. Β· Structured learning Β· Free forever.
πŸ“ Part of: React.js β†’ Topic 20 of 23
Next.
πŸ”₯ Advanced β€” solid JavaScript foundation required
In this tutorial, you'll learn
Next.
  • Next.js 16 requires React 19 β€” upgrade React before upgrading Next.js
  • Next.js 16 enforces no-store default for fetch() (introduced in v15) β€” audit every fetch call
  • Turbopack replaces Webpack as default β€” migrate webpack config to turbopack config
✦ Plain-English analogy ✦ Real code with output ✦ Interview questions
⚑Quick Answer
  • Next.js 16 ships with React 19, Partial Prerendering (stable), and Turbopack as default bundler
  • Partial Prerendering combines static shell with dynamic streaming in a single response
  • React 19 brings use() hook, enhanced Server Actions, and React Compiler (experimental)
  • Fetch caching default changed in v15 (not v16) β€” from force-cache to no-store, explicit cache required in v16
  • Turbopack replaces Webpack as the default dev and build bundler
  • Biggest mistake: upgrading from v14 to v16 without auditing fetch β€” every request hits origin
🚨 START HERE
Next.js 16 Quick Debug Reference
Fast commands for diagnosing Next.js 16 issues
🟑Fetch responses not cached
Immediate ActionAudit fetch cache behavior
Commands
grep -rn 'fetch(' app/ --include='*.tsx' --include='*.ts' | grep -v 'cache'
Add cache: 'force-cache' or revalidate: N to each fetch
Fix NowEvery fetch without explicit cache option uses no-store by default in Next.js 15+ (enforced in 16)
🟑Turbopack build failing
Immediate ActionFall back to Webpack and identify incompatibilities
Commands
npx next build --no-turbopack
npx @next/codemod@latest turbo-migrate
Fix NowRun the codemod to identify and fix Turbopack incompatibilities
🟑React 19 hydration errors
Immediate ActionCheck for mismatched Server and Client component boundaries
Commands
npx next lint --fix
grep -rn 'useState\|useEffect' app/ --include='*.tsx' | grep -v 'use client'
Fix NowComponents using hooks must have 'use client' directive at the top of the file
🟑Bundle size increased after upgrade
Immediate ActionAnalyze bundle with Turbopack stats
Commands
npx next build --debug
ANALYZE=true npx next build
Fix NowTurbopack typically produces smaller bundles β€” check for accidental client-side imports
Production IncidentNext.js 14 to 16 Upgrade Broke API Caching and Doubled Server CostsAn e-commerce platform jumped from Next.js 14 to 16 and saw API response times increase 3x because they missed the v15 fetch caching change β€” every request started hitting the origin server.
SymptomAfter deploying Next.js 16, the product listing page load time increased from 400ms to 1.2 seconds. Origin server CPU usage spiked from 30% to 85%. CDN cache hit ratio dropped from 92% to 15%. Monthly API costs doubled within one week.
AssumptionThe team blamed Turbopack β€” assuming the new default bundler in Next.js 16 introduced a production performance regression.
Root causeNext.js 15 changed fetch() default caching from force-cache to no-store in October 2024. The team was on Next.js 14, where 47 fetch calls relied on implicit caching. They upgraded directly to Next.js 16, skipping the v15 release notes. With no explicit cache options, all 47 fetches became uncached in production. Next.js 16 didn't introduce the change β€” it exposed the v15 breaking change during the Turbopack-enabled build.
FixAudited all 47 fetch calls and classified by cache requirement. Added cache: 'force-cache' to 32 fetches for static reference data. Added next: { revalidate: 3600 } to 12 fetches for product catalog data. Kept cache: 'no-store' on 3 fetches for real-time inventory. Added 'use cache' directive to 4 expensive Server Components. Response times dropped to 320ms β€” faster than v14 due to Turbopack's smaller bundle.
Key Lesson
The fetch caching default changed in Next.js 15, not 16 β€” a 14β†’16 jump inherits this breaking changeImplicit caching hides performance dependencies β€” always use explicit cache optionsTest CDN cache hit ratios in staging before any major version jumpTurbopack in Next.js 16 actually improved performance once caching was fixed
Production Debug GuideCommon symptoms after upgrading to Next.js 16
API response times increased 2-3x after upgrade→Check fetch caching defaults. Next.js 15+ uses no-store by default (changed from v14). Add explicit cache: 'force-cache' or revalidate: N to fetches that should be cached.
Build fails with Turbopack errors→Run next build --no-turbopack to fall back to Webpack temporarily. Check for unsupported Webpack loaders or plugins. Migrate to Turbopack-compatible alternatives.
Server Components render differently than before→Check for client component boundaries. React 19 changed how Server Components handle Suspense. Verify that 'use client' directives are on the correct components.
Partial Prerendering not working — page loads entirely dynamically→Verify that dynamic content is wrapped in a Suspense boundary. Static shell must be outside Suspense. Check that the route uses the experimental_ppr flag or PPR is enabled in next.config.
TypeScript errors after upgrade→Update @types/react to version 19. Update next-env.d.ts. Run npx next lint --fix. Check for deprecated type imports from next/app.

Next.js 16 is a major release that changes how applications are built, cached, and rendered. It ships with React 19 as the minimum version, Turbopack as the default bundler, and Partial Prerendering as a stable rendering strategy.

These changes are not incremental β€” they alter fundamental defaults that existing applications depend on. Fetch caching behavior changed. The bundler changed. The rendering model expanded. Applications upgrading from Next.js 14 or 15 without understanding these shifts will encounter broken caching, slower builds, and unexpected rendering behavior.

Tested on Next.js 16.0.0-canary, React 19.0.0.

React 19 Integration

Next.js 16 requires React 19 as the minimum version. This is not a peer dependency bump β€” React 19 changes how components render, how data flows, and how the compiler optimizes code.

The three most impactful React 19 features in Next.js 16 are enhanced Server Actions (stable since Next.js 14, with useActionState and improved Form handling in React 19), the use() hook for reading promises and context in conditional logic, and the React Compiler (experimental integration) that eliminates the need for useMemo and useCallback in most cases.

Server Actions replace API route handlers for form submissions and mutations. The use() hook replaces useEffect-based data fetching patterns for Server Component data. The React Compiler automatically memoizes components, removing a major source of performance bugs.

io.thecodeforge.nextjs16.react19.tsx Β· TYPESCRIPT
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
// ============================================
// React 19 Features in Next.js 16
// ============================================

// ---- 1. Server Actions ----
// Server Actions run on the server, called directly from components

'use server'

import { redirect } from 'next/navigation'
import { revalidatePath } from 'next/cache'

export async function createOrder(formData: FormData) {
  const productId = formData.get('productId') as string
  const quantity = parseInt(formData.get('quantity') as string, 10)

  if (!productId || quantity < 1) {
    return { error: 'Invalid input' }
  }

  try {
    await fetch('https://api.internal.io/orders', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ productId, quantity }),
    })

    revalidatePath('/orders')
    redirect('/orders/confirmation')
  } catch (err) {
    return { error: 'Order creation failed' }
  }
}

// ---- 2. use() Hook ----
// Read promises and context conditionally (unlike useContext)

import { use, Suspense } from 'react'

interface Product {
  id: string
  name: string
  price: number
}

async function fetchProduct(id: string): Promise<Product> {
  const res = await fetch(
    `https://api.internal.io/products/${id}`,
    { next: { revalidate: 60 } }
  )
  if (!res.ok) throw new Error('Product not found')
  return res.json()
}

function ProductCard({ productPromise }: {
  productPromise: Promise<Product>
}) {
  // use() unwraps the promise β€” can be called conditionally
  const product = use(productPromise)

  return (
    <div>
      <h2>{product.name}</h2>
      <p>${product.price.toFixed(2)}</p>
    </div>
  )
}

export default function ProductPage({
  params
}: {
  params: { id: string }
}) {
  const productPromise = fetchProduct(params.id)

  return (
    <Suspense fallback={<div>Loading product...</div>}>
      <ProductCard productPromise={productPromise} />
    </Suspense>
  )
}

// ---- 3. Form Component with Server Actions ----
// React 19 Form component handles pending states automatically

import { useFormStatus } from 'react-dom'

function SubmitButton() {
  const { pending } = useFormStatus()

  return (
    <button type="submit" disabled={pending}>
      {pending ? 'Placing order...' : 'Place order'}
    </button>
  )
}

export function OrderForm({ productId }: { productId: string }) {
  return (
    <form action={createOrder}>
      <input type="hidden" name="productId" value={productId} />
      <label>
        Quantity:
        <input
          type="number"
          name="quantity"
          defaultValue={1}
          min={1}
          max={100}
        />
      </label>
      <SubmitButton />
    </form>
  )
}
Mental Model
React 19 as a Server-First Framework
React 19 treats the server as the default β€” Server Actions, use() hook, and the compiler all optimize for server-first patterns.
  • Server Actions eliminate API route handlers for mutations β€” direct server functions from components
  • use() hook replaces useEffect for data fetching β€” promises unwrap inside components
  • React Compiler auto-memoizes β€” useMemo and useCallback become unnecessary in most cases
  • Form component handles pending states β€” no manual loading state management
  • useActionState replaces useReducer for form state with built-in error handling
πŸ“Š Production Insight
React Compiler (experimental) eliminates manual memoization β€” but it cannot memoize everything.
Components with side effects or external state still need explicit optimization.
Rule β€” do not pre-optimize with useMemo.
🎯 Key Takeaway
React 19 makes server-first patterns the default in Next.js 16.
Server Actions (enhanced in React 19) replace API routes for mutations β€” simpler and type-safe.
The React Compiler (experimental) removes the need for manual useMemo and useCallback.

Partial Prerendering (PPR)

Partial Prerendering is the most significant rendering innovation in Next.js 16. It combines static and dynamic rendering in a single response β€” the static shell is served instantly from the edge, while dynamic content streams: let the compiler work, then profile in via React Suspense.

PPR solves the fundamental tension between static performance and dynamic content. Traditional static generation serves fast pages but cannot show personalized data. Traditional server-side rendering shows personalized data but adds server latency to every request. PPR does both β€” the static parts render at build time, the dynamic parts render at request time.

The implementation requires wrapping dynamic content in Suspense boundaries. Everything outside Suspense is pre-rendered statically. Everything inside Suspense streams dynamically. Next.js automatically splits the response into static and dynamic chunks.

io.thecodeforge.nextjs16.ppr.tsx Β· TYPESCRIPT
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
// ============================================
// Partial Prerendering in Next.js 16
// ============================================

// ---- next.config.ts ----
// Enable PPR for the entire application
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  experimental: {
    ppr: true,
  },
}

export default nextConfig

// ---- Product Page with PPR ----
// Static shell renders at build time
// Dynamic sections stream at request time
import { Suspense } from 'react'

// Static component β€” rendered at build time, served from edge
function ProductHeader({ name, description }: {
  name: string
  description: string
}) {
  return (
    <header>
      <h1>{name}</h1>
      <p>{description}</p>
    </header>
  )
}

// Static component β€” rendered at build time
function ProductImages({ images }: { images: string[] }) {
  return (
    <div className="product-images">
      {images.map((src, i) => (
        <img key={i} src={src} alt={`Product image ${i + 1}`} />
      ))}
    </div>
  )
}

// Dynamic component β€” rendered at request time
async function ProductPrice({ productId }: { productId: string }) {
  // This fetch runs at request time β€” price may change
  const res = await fetch(
    `https://api.internal.io/products/${productId}/price`,
    { cache: 'no-store' }
  )
  const { price, currency, inStock } = await res.json()

  return (
    <div className="product-price">
      <span className="price">{currency} {price.toFixed(2)}</span>
      <span className={inStock ? 'in-stock' : 'out-of-stock'}>
        {inStock ? 'In Stock' : 'Out of Stock'}
      </span>
    </div>
  )
}

// Dynamic component β€” rendered at request time
async function PersonalizedRecommendations({
  userId
}: {
  userId: string
}) {
  const res = await fetch(
    `https://api.internal.io/recommendations/${userId}`,
    { cache: 'no-store' }
  )
  const recommendations = await res.json()

  return (
    <div className="recommendations">
      <h3>Recommended for you</h3>
      {recommendations.map((rec: any) => (
        <div key={rec.id}>{rec.name}</div>
      ))}
    </div>
  )
}

// Dynamic component β€” rendered at request time
async function AddToCartForm({ productId }: { productId: string }) {
  return (
    <form action={addToCart}>
      <input type="hidden" name="productId" value={productId} />
      <button type="submit">Add to Cart</button>
    </form>
  )
}

// Page component β€” PPR splits static and dynamic automatically
export default async function ProductPage({
  params
}: {
  params: { id: string }
}) {
  // This fetch can be cached β€” product data rarely changes
  const product = await fetch(
    `https://api.internal.io/products/${params.id}`,
    { next: { revalidate: 3600 } }
  ).then(r => r.json())

  return (
    <main>
      {/* STATIC: rendered at build time */}
      <ProductHeader
        name={product.name}
        description={product.description}
      />
      <ProductImages images={product.images} />

      {/* DYNAMIC: streamed at request time */}
      <Suspense fallback={<div>Loading price...</div>}>
        <ProductPrice productId={params.id} />
      </Suspense>

      <Suspense fallback={<div>Loading cart...</div>}>
        <AddToCartForm productId={params.id} />
      </Suspense>

      <Suspense fallback={<div>Loading recommendations...</div>}>
        <PersonalizedRecommendations userId="demo-user" />
      </Suspense>
    </main>
  )
}
Mental Model
PPR as Static Shell + Dynamic Streaming
PPR serves the static shell instantly from the edge, then streams dynamic content as it resolves β€” best of both worlds.
  • Everything outside Suspense is pre-rendered statically at build time
  • Everything inside Suspense is rendered dynamically at request time
  • The user sees the static shell immediately β€” no blank page waiting for server
  • Dynamic content streams in as each Suspense boundary resolves
  • Edge CDN serves the static shell β€” sub-100ms TTFB globally
πŸ“Š Production Insight
PPR requires careful Suspense boundary placement β€” too few boundaries means slow streaming.
Each Suspense boundary is an independent streaming chunk.
Rule: wrap every dynamic section in its own Suspense boundary for optimal streaming.
🎯 Key Takeaway
PPR combines static generation and dynamic rendering in a single response.
Static shell serves from the edge β€” dynamic content streams via Suspense.
Suspense boundary placement determines streaming granularity and perceived performance.

Turbopack as Default Bundler

Turbopack replaces Webpack as the default bundler in Next.js 16 for both development and production builds. This is not an experimental flag β€” Turbopack is the default, and Webpack is the fallback.

Turbopack is written in Rust and provides significant performance improvements over Webpack. Development server cold starts are 5-10x faster. Incremental rebuilds are near-instant. Production builds are faster and produce smaller bundles due to more aggressive tree-shaking.

The migration from Webpack to Turbopack is mostly transparent for standard Next.js applications. Custom Webpack configurations in next.config.js need to be migrated to Turbopack equivalents. Some Webpack loaders and plugins are not compatible and need replacement.

io.thecodeforge.nextjs16.turbopack.ts Β· TYPESCRIPT
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
// ============================================
// Turbopack Configuration in Next.js 16
// ============================================

// ---- next.config.ts ----
// Turbopack is the default β€” no flag needed
// Webpack fallback available with --no-turbopack flag

import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  // Turbopack configuration (replaces webpack config)
  turbopack: {
    // Resolve aliases (replaces webpack resolve.alias)
    resolveAlias: {
      '@components': './src/components',
      '@utils': './src/utils',
      '@hooks': './src/hooks',
    },

    // Module rules (replaces webpack module.rules)
    rules: {
      '*.svg': {
        test: /\.svg$/,
        use: ['@svgr/webpack'],
        as: '*.js',
      },
    },
  },

  // Standard Next.js config works with Turbopack
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'cdn.example.com',
      },
    ],
  },

  // Transpile packages (works with both Turbopack and Webpack)
  transpilePackages: ['@acme/ui', '@acme/utils'],
}

export default nextConfig

// ---- Webpack to Turbopack Migration ----
// Common patterns that need migration
// BEFORE (Webpack):
// module.exports = {
//   webpack: (config, { buildId, dev, isServer }) => {
//     config.resolve.alias['@'] = path.resolve(__dirname, 'src')
//     config.module.rules.push({
//       test: /\.svg$/,
//       use: ['@svgr/webpack'],
//     })
//     return config
//   }
// }

// AFTER (Turbopack): Use turbopack config in next.config.ts
// No webpack callback β€” use declarative turbopack config above

// ---- Turbopack-Compatible Alternatives ----

// Webpack loader -> Turbopack equivalent
// css-loader -> Built-in (no config needed)
// file-loader -> Built-in (use ?url suffix)
// raw-loader -> Built-in (use ?raw suffix)
// @svgr/webpack -> turbopack.rules with as: '*.js'
// babel-loader -> Built-in (SWC handles transforms)
// ts-loader -> Built-in (SWC handles TypeScript)

// ---- Build Commands ----
// Development (Turbopack default):
//   npx next dev
//
// Development (Webpack fallback):
//   npx next dev --no-turbopack
//
// Production build (Turbopack default):
//   npx next build
//
// Production build (Webpack fallback):
//   npx next build --no-turbopack
//
// Debug build with Turbopack stats:
//   npx next build --debug
⚠ Turbopack Migration Pitfalls
πŸ“Š Production Insight
Turbopack produces smaller production bundles than Webpack in most cases.
But some Webpack optimizations (Module Federation, custom plugins) are not available.
Rule: test production bundle size comparison before committing to Turbopack.
🎯 Key Takeaway
Turbopack is the default bundler in Next.js 16 β€” Webpack is the fallback.
Development builds are 5-10x faster β€” production bundles are typically smaller.
Custom webpack() configs must be migrated to the declarative turbopack config.

Caching Changes

Next.js 15 changed the default caching behavior for fetch() requests β€” a breaking change that causes most incidents during Next.js 16 upgrades. In Next.js 14 and earlier, fetch was cached by default (force-cache). Starting in Next.js 15, fetch uses no-store by default β€” every request hits the origin server unless you explicitly opt into caching.

Next.js 16 does not change the default again, but it enforces the explicit caching model and adds new APIs: the 'use cache' directive and cacheLife profiles for fine-grained, component-level control. Combined with Turbopack as the default bundler, a direct upgrade from v14 to v16 surfaces uncached fetches immediately as origin load spikes.

This remains the #1 upgrade risk because applications built on v14 relied on implicit caching. The v15+ model is predictable: you must choose force-cache, revalidate: N, or no-store for every fetch.

io.thecodeforge.nextjs16.caching.ts Β· TYPESCRIPT
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
// ============================================
// Next.js 15+ Caching (Critical for v16 Upgrades)
// ============================================

// ---- BEFORE (Next.js 14 and earlier) ----
// fetch was cached by default
// const data = await fetch('https://api.example.com/products')
// Implicitly: { cache: 'force-cache' }

// ---- AFTER (Next.js 15 and 16) ----
// fetch uses no-store by default
// const data = await fetch('https://api.example.com/products')
// Now: { cache: 'no-store' } β€” hits origin every time

// ---- Explicit Caching Patterns (Required) ----

// 1. Permanent cache (force-cache)
// Use for: static data that never changes
const countries = await fetch('https://api.example.com/countries', {
  cache: 'force-cache',
})

// 2. Time-based cache (revalidate)
// Use for: data that changes periodically
const products = await fetch('https://api.example.com/products', {
  next: { revalidate: 3600 }, // Cache for 1 hour
})

// 3. Tag-based cache (revalidateTag)
// Use for: data invalidated by events
const order = await fetch(`https://api.example.com/orders/${orderId}`, {
  next: { tags: ['orders', `order-${orderId}`] },
})

import { revalidateTag } from 'next/cache'

export async function updateOrder(orderId: string, data: any) {
  await fetch(`https://api.example.com/orders/${orderId}`, {
    method: 'PUT',
    body: JSON.stringify(data),
  })
  revalidateTag(`order-${orderId}`)
  revalidateTag('orders')
}

// 4. No cache (no-store)
// Use for: real-time data that must be fresh
const stockPrice = await fetch('https://api.example.com/stock/AAPL', {
  cache: 'no-store',
})

// ---- New in Next.js 16: cacheLife API ----
// Define reusable profiles in next.config.ts:
// experimental: {
//   cacheLife: {
//     static: { stale: Infinity },
//     frequent: { stale: 60, revalidate: 10 },
//     standard: { stale: 300, revalidate: 60 },
//   }
// }

import { cacheLife } from 'next/cache'

export async function ProductList() {
  'use cache'
  cacheLife('standard')

  const products = await fetch('https://api.example.com/products')
  return products.json()
}
⚠ Critical: Fetch Caching Changed in v15, Not v16
πŸ“Š Production Insight
The v15 caching change is the #1 cause of 14β†’16 upgrade failures.
A 50-fetch app on v14 becomes 50 uncached origin requests in v16.
Rule: run the fetch audit on v14, add explicit caching, then upgrade to v16.
🎯 Key Takeaway
Next.js 15 changed fetch from force-cache to no-store β€” Next.js 16 keeps this default.
Every fetch in v16 must have explicit cache configuration.
Use 'use cache' and cacheLife in Next.js 16 for fine-grained component caching.

Improved Image and Font Handling

Next.js 16 improves the next/image component with automatic AVIF/WebP format selection, responsive image generation, and blur-up placeholders. The next/font module now supports variable fonts natively and provides zero-layout-shift font loading.

These improvements reduce Largest Contentful Paint (LCP) and Cumulative Layout Shift (CLS) β€” two Core Web Vitals metrics that directly impact SEO rankings. The image component now generates srcset and sizes attributes automatically based on the image container width.

io.thecodeforge.nextjs16.images_fonts.tsx Β· TYPESCRIPT
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
// ============================================
// Next.js 16 Image and Font Improvements
// ============================================

// ---- Optimized Image Component ----
import Image from 'next/image'

export function ProductGallery({ images }: { images: string[] }) {
  return (
    <div className="gallery">
      {images.map((src, index) => (
        <Image
          key={index}
          src={src}
          alt={`Product image ${index + 1}`}
          width={800}
          height={600}
          // Automatic format selection (AVIF > WebP > original)
          priority={index === 0} // First image loads eagerly
          placeholder="blur"
          blurDataURL="data:image/jpeg;base64,/9j/4AAQ..."
          sizes="(max-width: 1200px) 50vw, 33vw"
          className="rounded-lg"
        />
      ))}
    </div>
  )
}

// ---- Remote Image with Loader ----
export function RemoteProductImage({
  src,
  alt
}: {
  src: string
  alt: string
}) {
  return (
    <Image
      src={src}
      alt={alt}
      width={400}
      height={300}
      loader={({ src, width, quality }) => {
        return `https://cdn.example.com${src}?w=${width}&q=${quality || 75}`
      }}
      sizes="(max-width: 768px) 100vw, 400px"
    />
  )
}

// ---- next/font with Variable Fonts ----
import { Inter, JetBrains_Mono } from 'next/font/google'

const inter = Inter({
  subsets: ['latin'],
  display: 'swap',
  variable: '--font-inter',
  // Variable font with specific axes
  axes: ['slnt'],
})

const jetbrains = JetBrains_Mono({
  subsets: ['latin'],
  display: 'swap',
  variable: '--font-mono',
})

// ---- Layout with Font Variables ----
export default function RootLayout({
  children
}: {
  children: React.ReactNode
}) {
  return (
    <html
      lang="en"
      className={`${inter.variable} ${jetbrains.variable}`}
    >
      <body className={inter.className}>
        {children}
      </body>
    </html>
  )
}

// ---- Using Font Variables in CSS ----
// app/globals.css:
// :root {
//   --font-sans: var(--font-inter);
//   --font-mono: var(--font-mono);
// }
//
// body {
//   font-family: var(--font-sans);
// }
//
// code, pre {
//   font-family: var(--font-mono);
// }
πŸ’‘Image and Font Performance Tips
  • Set priority={true} on above-the-fold images β€” they load eagerly with high fetch priority
  • Use sizes attribute to prevent loading oversized images on mobile
  • next/font eliminates layout shift β€” fonts self-host with automatic subsetting
  • Variable fonts reduce HTTP requests β€” one file covers all weights and styles
  • Blur placeholder provides instant visual feedback while the image loads
πŸ“Š Production Insight
Missing sizes attribute causes the browser to download the largest image variant on every device.
A 2400px image downloaded on a 375px mobile screen wastes bandwidth and slows LCP.
Rule: always set sizes based on your CSS layout breakpoints.
🎯 Key Takeaway
next/image generates responsive srcset automatically based on container width.
next/font self-hosts Google Fonts with zero layout shift and automatic subsetting.
Both components directly improve Core Web Vitals scores for SEO.
πŸ—‚ Next.js 15 vs Next.js 16 Key Changes
Understanding what changed and what it means for your application
FeatureNext.js 15Next.js 16Migration Impact
React VersionReact 18 or 19React 19 requiredUpdate @types/react, fix hydration issues
Default BundlerWebpackTurbopackMigrate webpack config to turbopack config
Fetch Cachingno-store by defaultno-store by defaultChange happened in v15 β€” audit all fetch calls if coming from v14
Partial PrerenderingExperimentalStableAdd Suspense boundaries around dynamic content
Server ActionsStableEnhanced with useActionStateReplace API routes with Server Actions
'use cache' DirectiveNot availableNew cache APIMark cacheable components with 'use cache'
React CompilerExperimentalExperimental integrationCompiler auto-memoizes β€” remove unnecessary useMemo/useCallback
Turbopack ConfigN/A (Webpack config)turbopack key in next.configReplace webpack() callback with turbopack object

🎯 Key Takeaways

  • Next.js 16 requires React 19 β€” upgrade React before upgrading Next.js
  • Next.js 16 enforces no-store default for fetch() (introduced in v15) β€” audit every fetch call
  • Turbopack replaces Webpack as default β€” migrate webpack config to turbopack config
  • Partial Prerendering combines static shell with dynamic streaming via Suspense
  • The 'use cache' directive provides component-level caching control
  • React Compiler (experimental) auto-memoizes β€” remove unnecessary useMemo and useCallback

⚠ Common Mistakes to Avoid

    βœ•Upgrading straight from Next.js 14 to Next.js 16 (skipping 15)
    Symptom

    Hitting two breaking changes at once: the fetch caching change from v15 PLUS Turbopack and other v16 defaults. Results in origin server overload, build failures, and unexpected rendering.

    Fix

    Upgrade incrementally (14 β†’ 15 first to fix caching, then to 16) OR perform a full audit for BOTH the v15 caching change and v16 Turbopack migration before deploying.

    βœ•Upgrading to Next.js 16 without auditing fetch cache behavior
    Symptom

    Origin server CPU spikes to 90%+, page load times increase 3-5x, CDN cache hit ratio drops from 90%+ to under 20%

    Fix

    grep -rn 'fetch(' app/ --include='.tsx' --include='.ts' | grep -v 'cache'. Add explicit cache: 'force-cache', next: { revalidate: N }, or cache: 'no-store' to every fetch call.

    βœ•Not installing React 19 before upgrading Next.js
    Symptom

    Build fails with peer dependency errors, or runtime crashes with missing React APIs like use() and useActionState

    Fix

    npm install react@19 react-dom@19 @types/react@19 @types/react-dom@19. Then upgrade next: npm install next@16.

    βœ•Keeping custom webpack() config when using Turbopack
    Symptom

    Custom webpack configuration is silently ignored β€” aliases, loaders, and plugins do not apply, causing build errors or missing imports

    Fix

    Migrate webpack config to turbopack config in next.config.ts. Use resolveAlias instead of resolve.alias. Use turbopack.rules instead of module.rules.

    βœ•Not wrapping dynamic content in Suspense for Partial Prerendering
    Symptom

    Entire page renders dynamically β€” no static shell, no streaming, slower than SSR. PPR provides no benefit without Suspense boundaries.

    Fix

    Wrap every dynamic section (price, recommendations, user-specific content) in its own Suspense boundary with a fallback UI.

    βœ•Using useMemo and useCallback with React Compiler enabled
    Symptom

    No functional issue but unnecessary code β€” the compiler auto-memoizes, making manual memoization redundant. Adds bundle size and cognitive overhead.

    Fix

    Remove manual useMemo and useCallback where the compiler handles optimization. Keep them only for values with expensive computation that the compiler cannot optimize.

    βœ•Not testing production build after switching to Turbopack
    Symptom

    Development works fine but production build fails or produces different behavior due to Turbopack's different optimization strategy

    Fix

    Always run npx next build and test the production output. Compare bundle size with npx next build --no-turbopack if issues arise.

Interview Questions on This Topic

  • QWhat are the major changes in Next.js 16 compared to Next.js 15?JuniorReveal
    Next.js 16 introduces several breaking changes: 1. React 19 is required β€” React 18 is no longer supported. This brings the use() hook, enhanced Server Actions with useActionState, and React Compiler (experimental). 2. Turbopack is the default bundler β€” replaces Webpack for both development and production. Custom webpack configs must be migrated to the turbopack config object. 3. Fetch caching default (changed in v15, enforced in v16) β€” v15 switched fetch from force-cache to no-store. Next.js 16 adds 'use cache' and cacheLife APIs. Every fetch without explicit options hits origin unless configured. 4. Partial Prerendering is stable β€” combines static shell with dynamic streaming via Suspense boundaries. 5. New 'use cache' directive and cacheLife API β€” provide fine-grained component-level caching control. The most disruptive change for v14 upgraders is the fetch caching default from v15.
  • QHow does Partial Prerendering work and when should you use it?Mid-levelReveal
    Partial Prerendering (PPR) combines static generation and dynamic rendering in a single HTTP response. Here is how it works: 1. At build time, Next.js pre-renders the static shell β€” everything outside Suspense boundaries becomes a static HTML shell served from the edge CDN. 2. At request time, the dynamic content inside Suspense boundaries is rendered on the server and streamed into the response using React's streaming SSR. 3. The user sees the static shell immediately (sub-100ms TTFB from edge), then dynamic content fills in as each Suspense boundary resolves. Use PPR when: - The page has a static structure (header, footer, product info) with dynamic sections (price, recommendations, user data) - You want edge-level performance for static parts while maintaining dynamic personalization - The page has multiple independent data sources that can stream in parallel Do not use PPR when: - The entire page is personalized are no Suspense boundaries β€” without them, PPR provides no benefit - All data must be present before rendering β€” PPR streams partial content
  • QYour team upgraded to Next.js 16 and API costs doubled. How do you diagnose and fix this?SeniorReveal
    Systematic diagnosis for post-upgrade cost increase: 1. Check fetch caching behavior: The most likely cause is the fetch caching default change introduced in Next.js 15 (enforced in 16). Run grep -rn 'fetch(' app/ to find all fetch calls. Check which ones lack explicit cache options. In Next.js 16, these default to no-store. 2. Measure origin server hit rate: Compare the CDN cache hit ratio before and after the upgrade. A drop from 90%+ to under 30% confirms the caching issue. 3. Audit fetch calls by category: - Static data (countries, config): Add cache: 'force-cache' - Periodic data (products, blog): Add next: { revalidate: 3600 } - Event-driven data (orders, user): Add next: { tags: ['orders'] } and use revalidateTag - Real-time data (stock, live): Keep cache: 'no-store' 4. Add the 'use cache' directive: For components that fetch and render expensive data, add 'use cache' with cacheLife('standard') to cache the entire component output. 5. Monitor after fix: Set up CloudWatch or Datadog alerts on origin request count. Verify that the CDN cache hit ratio returns to the pre-upgrade baseline. The fix typically takes 1-2 hours β€” it is a systematic audit of fetch calls, not a complex debugging session.
  • QWhat is the React Compiler and how does it change Next.js development?Mid-levelReveal
    The React Compiler (formerly React Forget) is a build-time optimization that automatically memoizes components. It analyzes your component code and inserts memoization where needed β€” replacing manual useMemo, useCallback, and React.memo calls. How it changes Next.js development: 1. Less boilerplate: You no longer need useMemo for derived values or useCallback for event handlers passed to child components. The compiler handles this automatically. 2. Fewer performance bugs: Manual memoization is error-prone β€” developers forget dependencies or over-memoize. The compiler gets it right by analyzing the actual data flow. 3. Simpler mental model: Instead of thinking about which values to memoize, you write straightforward code and let the compiler optimize. In Next.js 16, the React Compiler is integrated (experimental) into the Turbopack build pipeline. It runs automatically during compilation β€” no configuration needed. Important limitation: The compiler cannot memoize components with side effects, external state subscriptions, or imperative DOM manipulation. For these cases, manual optimization may still be needed.

Frequently Asked Questions

Can I still use Webpack in Next.js 16?

Yes, Webpack is available as a fallback. Run next dev --no-turbopack or next build --no-turbopack to use Webpack. However, Webpack support will be deprecated in future versions. Migrate to Turbopack when possible β€” it provides faster builds and smaller bundles.

Do I have to use Partial Prerendering in Next.js 16?

No, PPR is opt-in. Enable it in next.config.ts with experimental: { ppr: true }. Without this flag, Next.js 16 uses the same rendering strategies as Next.js 15 (SSR, SSG, ISR). PPR is recommended for pages with a mix of static and dynamic content.

What happens if I do not change my fetch calls after upgrading?

Every fetch call without an explicit cache option will use no-store β€” meaning it hits the origin server on every request. This can cause dramatic performance degradation and increased server costs. Always audit fetch calls before upgrading.

Is the React Compiler enabled by default in Next.js 16?

Yes, the React Compiler runs automatically during the Turbopack build process (experimental). No configuration is needed. It analyzes your components and inserts memoization where beneficial. If you are using Webpack fallback, the compiler is not available.

How do I migrate from next.config.js with webpack() to Turbopack?

Replace the webpack() callback function with a declarative turbopack object in next.config.ts. Key mappings: resolve.alias becomes turbopack.resolveAlias, module.rules becomes turbopack.rules, and plugins need Turbopack-compatible alternatives. Run npx @next/codemod@latest turbo-migrate to identify incompatible configurations.

πŸ”₯
Naren Founder & Author

Developer and founder of TheCodeForge. I built this site because I was tired of tutorials that explain what to type without explaining why it works. Every article here is written to make concepts actually click.

← PreviousReact 19 New FeaturesNext β†’Partial Prerendering in Next.js 16 β€” The Complete Guide
Forged with πŸ”₯ at TheCodeForge.io β€” Where Developers Are Forged