mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #256] fix(ssr): first request after server start always returns 500 #66
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#66
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @gagipro on GitHub (Mar 5, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/256
Bug Description
The first HTTP request after starting the vinext production server (
vinext start) always returns a 500 Internal Server Error. All subsequent requests succeed with 200. This is 100% reproducible on every server restart.Root Cause
During production SSR, client reference modules (
"use client"components) are loaded lazily via asyncimport()through thesetRequireModule({ load })mechanism provided by@vitejs/plugin-rsc. On the very first request:handleSsrcallscreateFromReadableStreamto create the React element tree from the RSC streamrenderToReadableStreamattempts to render the HTML shell synchronously__vite_rsc_client_require__(id)which returns a Promise (the asyncimport()has not completed yet)<Suspense>boundary wrapping the root shell, React SSR cannot render a fallback — it rejects withundefinedonErrorcallback receivesundefined, andrenderToReadableStreamrejects"Server error: undefined"and returns 500On subsequent requests, the modules are already cached by the
memoize()wrapper insetRequireModule, so__vite_rsc_client_require__resolves synchronously from cache and SSR succeeds.Steps to Reproduce
"use client"components:vinext buildvinext startcurl http://localhost:3120/curl http://localhost:3120/This reproduces on every restart cycle —
systemctl restart/vinext start/ any cold start.Environment
Proposed Fix
Eagerly preload all client reference modules at the start of
handleSsr, beforerenderToReadableStreamruns. Thevirtual:vite-rsc/client-referencesmodule (provided by@vitejs/plugin-rsc) exposes the map of all client component IDs to their async import functions. By calling__vite_rsc_client_require__for each ID before rendering, the memoize cache is warmed and all subsequentrequirecalls during SSR resolve synchronously.The fix is minimal (16 lines, single file) and has no impact on subsequent requests since
memoize()returns cached values immediately.PR incoming: #TBD