vinext is a Vite plugin that reimplements the Next.js API surface, allowing existing Next.js applications to run on a completely different toolchain. This page explains how vinext works under the hood.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/vinext/llms.txt
Use this file to discover all available pages before exploring further.
Core Architecture
vinext is a Vite plugin that performs four key functions:Module Resolution
Resolves all
next/* imports to local shim modules that reimplement the Next.js API using standard Web APIs and React primitives.File-System Routing
Scans your
pages/ and app/ directories to build a file-system router matching Next.js conventions.Virtual Entry Generation
Generates virtual entry modules for the RSC, SSR, and browser environments that handle request routing, component rendering, and client hydration.
Request Flow
Pages Router Flow
The Pages Router flow is straightforward:- Request arrives at the Vite dev server middleware
- Route matching finds the appropriate page component based on the URL
- Data fetching executes
getServerSidePropsorgetStaticPropsif defined - Rendering calls React’s
renderToReadableStreamwith the_appand page components - HTML generation embeds serialized page props in
__NEXT_DATA__script tag - Client hydration picks up the props and hydrates the React tree
App Router Flow
The App Router flow involves two separate Vite environments:-
RSC entry (runs in the
rscVite environment withreact-servercondition)- Matches the URL to an app route
- Builds the nested layout + page component tree
- Renders to an RSC stream
-
SSR entry (runs in the
ssrVite environment)- Consumes the RSC stream
- Renders to HTML with
renderToReadableStream - Embeds RSC payload for client hydration
- Client hydration picks up the RSC stream and hydrates interactive components
Project Structure
Module Shims
Everynext/* import is shimmed to a Vite-compatible implementation:
next/* modules are implemented this way, providing the full Next.js API surface on top of Vite.
Division of Responsibilities
What @vitejs/plugin-rsc Handles
The RSC plugin from Vite handles the React Server Components infrastructure:
- Bundler transforms for
"use client"/"use server"directives - RSC stream serialization (wraps
react-server-dom-webpack) - Multi-environment builds (RSC/SSR/Client)
- CSS code-splitting and auto-injection
- HMR for server components
- Bootstrap script injection for client hydration
What vinext Handles
vinext handles everything else that makes it Next.js:- File-system routing (scanning
app/andpages/directories) - Request lifecycle (middleware, headers, redirects, rewrites, then route handling)
- Layout nesting and React tree construction
- Client-side navigation and prefetching
- Caching (ISR,
"use cache", fetch cache) - All
next/*module shims - CLI commands (dev, build, deploy, etc.)
Virtual Modules
vinext generates several virtual modules that serve as entry points:| Module | Purpose | Environment |
|---|---|---|
virtual:vinext-rsc-entry | RSC request handler for App Router | rsc |
virtual:vinext-app-ssr-entry | SSR entry for App Router | ssr |
virtual:vinext-app-browser-entry | Client hydration for App Router | client |
virtual:vinext-server-entry | Pages Router SSR handler | ssr |
virtual:vinext-client-entry | Client hydration for Pages Router | client |
Virtual module IDs are prefixed with
\0 when resolved by Vite. The resolveId hook must handle both unprefixed and prefixed forms.Production Builds
Production builds require special handling due to the multi-environment architecture:buildApp() triggers the RSC plugin’s 5-step build sequence:
- RSC build — Server components (react-server condition)
- SSR build — SSR entry and server-side client components
- Client build — Browser bundle with client components
- RSC client manifest — Mapping of client component IDs
- SSR client manifest — For SSR environment to reference client chunks
Deployment Target
Cloudflare Workers is the primary deployment target:vinext deploy command handles the full build-and-deploy pipeline, including:
- Auto-generating configuration files (
vite.config.ts,wrangler.jsonc,worker/index.ts) - Detecting and fixing common migration issues
- Building the application for Workers
- Deploying to Cloudflare
Next Steps
File-System Routing
Learn how vinext scans your pages/ and app/ directories
Server Components
Understand RSC integration and rendering flow
Caching & ISR
Explore the pluggable cache architecture
API Coverage
See which Next.js APIs are supported