Next.js in open-source AI tools: the framework behind Dify, Langfuse, LobeChat and Cal.com in 2026
What Next.js does
Next.js wraps React with the pieces a production web app needs: file-based routing, server-side rendering, static generation, API routes, image optimization, and a build system. Since version 13, its App Router runs React Server Components, which render on the server and send finished HTML and data to the browser, while client components handle interaction. For AI apps this split is natural: the server holds API keys and talks to models and databases, and the client shows the chat.
Which directory projects use it
| Project | What it is | Next.js role |
|---|---|---|
| Dify | LLM app and agent platform | Web front end; back end is Python |
| Langfuse | LLM tracing and evaluation | Full web app and API |
| LobeChat | Multi-provider chat | Full app with server routes for providers |
| Morphic | AI answer engine with search | Full app using the Vercel AI SDK |
| Cal.com | Scheduling platform with AI features | Web app in a large monorepo |
Next.js 16
Next.js 16, released in October 2025, made Turbopack the default bundler for development and builds, introduced Cache Components with an explicit use cache directive, and renamed middleware to proxy. The 16.x line has continued with point releases. Next.js 16.4 enabled Cache Components by default for new projects created with create-next-app, and expanded tooling designed to let AI coding agents run framework upgrades. Next.js 16.4.2, on October 15, 2026, backported stability fixes following an October security update.
For self-hosted AI apps, these versions matter mostly through the projects that use them. Dify, Langfuse and LobeChat each choose when to move to a new Next.js release, and you get the change when you upgrade the project.
Streaming AI responses
Next.js supports streaming at several levels. Route handlers can return a ReadableStream, so a server route can forward a model's token stream directly to the browser. Server components can stream HTML in chunks with React Suspense, which lets a dashboard show its layout instantly while slow queries finish. The Vercel AI SDK's streamText function and useChat hook wrap this into a few lines: the route calls a model and returns a stream, and the hook renders messages as they arrive, including tool calls and their results.
When self-hosting behind a reverse proxy such as Nginx, turn off response buffering for streaming routes, or replies will arrive all at once at the end. This is the most common streaming problem in self-hosted Next.js AI apps.
Self-hosting Next.js
Next.js is MIT-licensed and does not require Vercel. To self-host:
- Set
output: "standalone"innext.config, which produces a minimal server bundle. - Build in Docker with a multi-stage image and run
node server.js. - Put a reverse proxy in front for TLS, and turn off buffering for streaming routes.
- If you run several instances, configure a shared cache handler, since the default cache is per-instance on disk.
- Serve static assets from a CDN for best performance, though the Node server can serve them.
Features that are easiest on Vercel, such as image optimization at scale, incremental static regeneration across regions and edge middleware, all work self-hosted with some configuration. The Next.js team has published an adapter API so other platforms such as Netlify, Cloudflare and AWS can support the framework fully.
Security
Next.js apps run server code, so framework vulnerabilities can be serious:
| Date | Issue | Impact |
|---|---|---|
| March 2025 | CVE-2025-29927, middleware bypass | Attackers could skip middleware-based auth checks with a crafted header |
| December 2025 | CVE-2025-55182, React Server Components | Critical remote code execution on servers using the App Router |
| October 2026 | Security update | Fixes followed by the 16.4.2 stability backport |
The December 2025 flaw, sometimes called React2Shell, was exploited in the wild within days of disclosure. Self-hosted AI apps often hold model API keys and database credentials on the same server, which makes them attractive targets. Practical steps: subscribe to release notifications for every self-hosted Next.js app you run, upgrade promptly when a security release lands, avoid relying only on middleware for authentication, and keep secrets in environment variables scoped to the server.
Performance and cost
A Next.js server typically uses 150 to 500 MB of memory. Server rendering adds CPU per request compared with a static front end, which matters little for internal tools and more for public, high-traffic apps. On Vercel, Hobby is free for personal, non-commercial use and Pro costs $20 a month plus usage; self-hosting on a small virtual server costs $5 to $20 a month. See the Vercel stack page for details.
Next.js and AI coding tools
Next.js is the default output of many AI app builders and coding agents, including v0, Bolt and Lovable, so a large share of AI-generated web apps are Next.js projects. That has a practical effect: when you ask Claude Code, Codex or Cursor to build a web interface for an AI tool, you will usually get Next.js unless you ask otherwise. Vercel publishes guidance and an MCP server for Next.js documentation to help agents use current APIs, since models trained on older data often produce Pages Router code or outdated patterns.
Common problems when self-hosting Next.js AI apps
| Symptom | Likely cause | Fix |
|---|---|---|
| Replies appear all at once | Proxy buffering | Set proxy_buffering off in Nginx for streaming routes, or send the X-Accel-Buffering: no header |
| Long agent runs cut off | Proxy or platform timeout | Raise proxy read timeouts; on serverless hosts, check the maximum function duration |
| Stale data after updates | Cached server components | Check the project's cache settings and revalidation; restart to clear the on-disk cache |
| Login loops behind a proxy | Wrong public URL | Set the app's base URL variable, such as NEXTAUTH_URL, to the public HTTPS address |
| Build fails in Docker | Memory limit during build | Give the build container 4 GB or more, or use the project's prebuilt image |
Most of these come from the layer in front of Next.js rather than the framework itself. Langfuse and Dify document recommended proxy settings; follow them before debugging application code.
Alternatives
| Framework | Language | Strength |
|---|---|---|
| Remix / React Router 7 | TypeScript | Web-standard data loading, simpler mental model |
| SvelteKit | TypeScript/Svelte | Small bundles; used by Open WebUI |
| Nuxt | TypeScript/Vue | The Vue equivalent of Next.js |
| Astro | TypeScript | Content sites with islands of interactivity |
| Vite + React SPA | TypeScript | No server rendering; simplest to host |
Open WebUI, the most popular Ollama front end, uses SvelteKit rather than Next.js, and LibreChat and AnythingLLM use React single-page apps built with Vite. There is no single right choice; Next.js wins on the number of libraries, examples and hosting options, and on AI SDK integration.
Contributing to Next.js AI projects
Expect a pnpm monorepo, TypeScript throughout, Tailwind or a component library for styles, and Playwright for end-to-end tests. Run the dev server with Turbopack for fast reloads. When changing server components, remember that code runs on the server and cannot use browser APIs, and that anything passed to client components is serialized and visible to users.
Related: React stack, Vercel stack, TypeScript stack, Tailwind CSS stack, Langfuse stack, Stack index.
Frequently asked questions
Why do AI apps use Next.js?
It handles the front end and a server layer in one project. Server routes can call model APIs with secret keys while React components stream the reply to the browser. Server components render data-heavy dashboards quickly, and the Vercel AI SDK integrates directly. It is also the framework most AI coding tools generate by default.
Can I self-host a Next.js app without Vercel?
Yes. Next.js runs on any Node.js server or in Docker using the standalone output mode, which bundles only the files the server needs. Dify, Langfuse and LobeChat all ship Docker images that run Next.js on your own infrastructure.
What was the React Server Components vulnerability?
In December 2025 a critical remote code execution flaw, CVE-2025-55182, was disclosed in React Server Components, affecting Next.js apps using the App Router. Attackers could run code on the server with a crafted request. Patched React and Next.js versions were released, and anyone running an affected app should have upgraded immediately.
Is Next.js required to use the Vercel AI SDK?
No. The AI SDK works with any JavaScript framework and plain Node.js, though its React helpers and documentation examples lean toward Next.js.
How do I update a self-hosted Next.js AI app?
Pull the project's latest release or Docker image, which bundles the patched Next.js version. You rarely update Next.js yourself in someone else's project; you update the project. Watch the project's releases page for security notes.