Next.js 12 — Major release: Rust compiler, Middleware, React 18 support
Key Points
- rust-based compiler: much faster builds
- edge middleware (beta) for request-time code
- experimental React 18 & server components support
Summary
Next.js 12 is a major release focused on build/runtime speed, edge-first middleware, and early support for React 18 features. It introduces a Rust-based compiler (SWC) for much faster builds and refresh, edge-capable Middleware (beta), experimental React 18 and Server Components support, URL imports/ESM improvements, AVIF image support, and output file tracing for standalone deployments.
Upgrade quickly: npm i next@latest.
Key Points
- Rust compiler (SWC): ~3x faster Fast Refresh and ~5x faster production builds;
swcMinify: trueenables faster minification. Backwards-compatible with custom Babel configs. - Middleware (beta): run code before a request completes (rewrite, redirect, headers, streaming). Create
pages/_middleware.jsand use standard Web APIs (Response, fetch). Works on Edge. - React 18 & Server Components (experimental): enable with
experimental.concurrentFeatures: trueandserverComponents: trueto try SSR streaming, Suspense and component-level data fetching. - ES Modules & URL Imports (experimental): ESM is default; import modules from URLs by allowing prefixes in
next.config.js(experimental.urlImports). Next.js generatesnext.lockand caches remote modules. - AVIF images: opt-in via
images.formats = ['image/avif','image/webp']for ~20% smaller images when supported. - Bot-aware ISR fallback: crawlers auto-render ISR pages (fallback: true) to avoid indexing loading states.
- Output file tracing: Next.js uses
@vercel/nftto trace and emit required files per page/route to simplify deployments and enable smaller standalone outputs. - Misc: support for
next.config.mjs, customtsconfig.jsonpath, improved Fast Refresh telemetry, single-filenext lint --file.
Breaking Changes & Notes
- Webpack 4 removed; webpack 5 is required. Test plugins/loaders for webpack 5 compatibility.
- Many features are experimental; enable explicitly and test before production use.
Practical Action Items
- Run
npm i next@latest, test local dev and production builds. - If using custom Babel, verify behavior; opt into SWC minifier with
swcMinify: truewhen ready. - Audit middleware, react-18 flags, and any webpack plugins for compatibility before upgrade.