React Server Components Integration
Vinext’s App Router implementation is built on top of@vitejs/plugin-rsc, which provides the bundler transforms and runtime infrastructure for React Server Components. This guide explains how the integration works and the patterns used.
RSC Entry Point
The RSC entry (virtual:vinext-rsc-entry) is the request handler for all App Router requests. It runs in the rsc Vite environment with the react-server import condition.
Request Handler Export
Frompackages/vinext/src/server/app-dev-server.ts:
- All async context uses
AsyncLocalStorage.run()for proper isolation - Headers and cookies are available via
headers()andcookies()throughout the tree - Per-request cache state is initialized once
- Fetch cache tracks tags for revalidation
Request Lifecycle
The_handleRequest function implements the full request lifecycle:
- Protocol-relative URL guard - Reject paths starting with
// - Base path stripping - Remove
basePathprefix if configured - Trailing slash normalization - Redirect to canonical form
- Config redirects - Apply
redirectsfrom next.config.js - beforeFiles rewrites - Apply before file-system routing
- Middleware execution - Run middleware.ts if path matches
- Image optimization - Handle
/_vinext/imageendpoint - Metadata routes - Serve sitemap.xml, robots.txt, manifest.json
- Server actions - Handle POST requests with
x-rsc-actionheader - afterFiles rewrites - Apply after file-system routing
- Route matching - Find matching App Router route
- fallback rewrites - Apply if no route matched
- Route handler execution - Run route.ts if present
- Page rendering - Build component tree and render to RSC stream
- SSR delegation - Pass RSC stream to SSR entry for HTML generation
Component Tree Rendering
Metadata Resolution
Metadata and viewport are resolved from layouts and pages before rendering:resolveModuleMetadata() handles both static exports and generateMetadata() functions:
Thenable Params
Next.js 15+ changedparams and searchParams to Promises. Vinext creates “thenable objects” for backward compatibility:
- Page component props
- Layout component props
generateMetadata()argumentsgenerateViewport()arguments
Boundary Components
Vinext wraps the component tree with error, loading, and not-found boundaries: Loading Boundary:Server Actions
Server actions are POST requests with thex-rsc-action header:
CSRF Protection
Vinext implements the same CSRF protection as Next.js:Action Execution
- Actions support both FormData and text bodies
- Temporary references enable streaming large payloads
redirect()in actions is detected via digest- Page is re-rendered after mutation to reflect changes
- Cookies set during action are attached to response
SSR Delegation
After rendering the RSC stream, the RSC entry delegates to the SSR entry for HTML generation:setNavigationContext() in the RSC environment doesn’t affect the SSR environment.
Client components rendered during SSR need pathname/searchParams/params. The SSR entry receives the context and calls its own setNavigationContext() before rendering.
Route Handlers
Route handlers (route.ts) are special-cased:Error Handling
RSC onError Callback
Vinext provides anonError callback to preserve digests for navigation errors:
onError returns undefined and the digest is lost. Client-side error boundaries can’t identify the error type (redirect, notFound, etc.).
Error Page Rendering
When a server component throws, Vinext renders the error boundary page:Next Steps
Architecture Deep Dive
Core architecture and design patterns
Build Pipeline
Production build pipeline details
Virtual Modules
Virtual module system and generation