Vercel has released version 12.2 of its Next.js React-based framework, with key features now stable and new experimental APIs.
Next.js is open source and can be self-hosted or deployed to Vercel’s edge network (hosted by AWS). Last October, the team previewed a feature called Middleware, explaining that “Middleware enables you to use code over configuration.”
It added: “This gives you full flexibility in Next.js because you can run code before a request is completed,” reversing the common assumption that configuration is more efficient than code.
Middleware runs on the Edge Runtime, a lightweight runtime based on the V8 engine which uses a cut-down API and only works with ES (ECMAScript) modules, not with native Node.js APIs. Vercel’s chief architect Malte Ubl said on Hacker News that Edge Functions has “startup-time so fast that if you hit a cold start it is still fast enough from a human perception (often <30ms attributable to startup).” The trade-off, he said, is the restricted API set, smaller maximum binary size, lower CPU quota and lower maximum RAM usage.
Middleware is now generally available, and Vercel’s CEO Guillermo Rauch said yesterday that “almost half of our enterprise customers” had made use of the beta.
Another feature now declared stable is on-demand incremental static regeneration, 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, with no need to rebuild an entire site. On demand means that a revalidation API can be called when content changes.
New in this version is Edge API routes, for building APIs using the same Next.js Edge Runtime used by Middleware. Edge API routes are in beta. Another new feature, designated as experimental, is an option to use Edge server rendering with the Edge Runtime instead of Node.js for server-side rendering of pages. The documentation states that the Edge Runtime has “lower latency as well as better scalability.”
A full description of what is new in 12.2 can be found here.
There are echoes here of the work being done by Vercel’s competitor Netlify and by the Deno team, building an alternative to Node.js based on TypeScript and web standard ES modules.
It is a modern serverless approach to web development: push the code, let the provider worry about where it runs, and use web standard APIs. Scalability is easier and there are security benefits, but as noted by Hacker News commenters, not all the code is open source and the hosting can be expensive.