Experimental and stable middleware APIs include plugins for Rust-based SWC • DEVCLASS
Vercel has released version 12.2 of its Next.js-based React framework, with key features now stable and new experimental APIs.
Next.js is open-source and can be self-hosted or deployed on Vercel’s edge network (hosted by AWS). Last October, the team previewed a feature called Middleware, explaining that “middleware allows you to use code rather than configuration”.
He added, “It gives you complete flexibility in Next.js because you can run code before a request completes,” overturning the common assumption that configuration is more efficient than code.
The middleware runs on Edge Runtime, a lightweight runtime based on the V8 engine that uses a reduced API and only works with ES (ECMAScript) modules, not native Node.js APIs. The Chief Architect of Vercel Malta Ubl said on Hacker News that Edge Functions has “such a fast boot time that if you cold boot it’s still quite fast from a human perspective (often
The middleware is now generally available and Vercel CEO Guillermo Rauch said yesterday that “almost half of our corporate customers” had used the beta version.
Another feature now declared stable is on-demand incremental static refresh, a feature added in beta in Next.js 12.1. Incremental means that static page regeneration can be done on a page-by-page basis, without the need to rebuild an entire site. On-demand means that a revalidation API can be called when the content changes.
New in this release is Edge API routes, for building APIs using the same Edge Next.js runtime used by Middleware. Edge API routes are in beta. Another new feature, marked as experimental, is an option to use Edge Server rendering with Edge Runtime instead of Node.js for server-side rendering of pages. The documentation states that Edge Runtime has “lower latency as well as better scalability”.
A complete description of the new features of version 12.2 is available here.
Here we find echoes of the work done by Vercel competitor Netlify and the Deno team, building an alternative to Node.js based on TypeScript and standard web-based ES modules.
It’s a modern serverless approach to web development: push the code, let the provider worry about where it’s running, and use standard web APIs. Scalability is easier and there are security benefits, but as Hacker News commenters noted, not all code is open source and hosting can be expensive.