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.

The GA version of Middleware has breaking changes from the beta version. Middleware functions can no longer be nested, but must now reside within a single root middleware, a code file written in TypeScript or JavaScript. The documents say it’s both faster and cheaper. It is still possible to execute code based on query paths or other conditions. Another change is that the middleware can no longer generate a response body, but instead must use rewriting or redirection to modify an incoming request. There are also changes in the cookie API.

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”.

SWC is a JavaScript or TypeScript compilation and bundling tool, written in Rust and claimed [https://swc.rs/ ] be 20 times faster than Babel on a single thread, or 70 times faster on four cores. SWC was developed by DongYoon Kang who was hired by Vercel last August. Build performance is critical for Next.js due to the requirement for fast server-side rebuilding. New in Next.js 12.2 is experimental support for plugins written in WebAssembly that customize the SWC transformation.

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.

Comments are closed.