[PR #546] [CLOSED] fix: eagerly preload client references to prevent first-request 500 #662

Closed
opened 2026-05-06 13:09:24 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/546
Author: @NathanDrake2406
Created: 3/15/2026
Status: Closed

Base: mainHead: fix/first-request-500


📝 Commits (3)

  • af5bc16 fix: eagerly preload client references to prevent first-request 500
  • 54a510e fix: remove brittle code-generation tests per review feedback
  • d538106 perf: skip client reference preloading after first request

📊 Changes

3 files changed (+100 additions, -0 deletions)

View changed files

📝 packages/vinext/src/entries/app-ssr-entry.ts (+20 -0)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+20 -0)
📝 tests/app-router.test.ts (+60 -0)

📄 Description

Summary

Fixes #256.

  • First SSR request after vinext start returns 500 because client reference modules are loaded lazily via async import() in @vitejs/plugin-rsc's memoize() cache
  • On the first request, __vite_rsc_client_require__ returns an unresolved Promise. Without a <Suspense> boundary wrapping the root shell, React SSR rejects. Subsequent requests work because the cache is warm.
  • Added eager preloading of all client reference modules in the generated SSR entry (app-ssr-entry.ts) via Promise.all before renderToReadableStream runs
  • Guarded with if (_clientReferences.default && globalThis.__vite_rsc_client_require__) for safety

Test plan

  • Behavioral test: verifies memoize cache warming strategy works (cold cache → preload → warm cache)
  • All 254 app-router tests pass
  • Snapshot updates are mechanical (preloading block added to SSR entry)
  • Typecheck and lint clean

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/546 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/first-request-500` --- ### 📝 Commits (3) - [`af5bc16`](https://github.com/cloudflare/vinext/commit/af5bc1645975d6bf2c4ab59049fc291c0e6b1c0e) fix: eagerly preload client references to prevent first-request 500 - [`54a510e`](https://github.com/cloudflare/vinext/commit/54a510e58465f971b2a6f9eabfbe60073c080d87) fix: remove brittle code-generation tests per review feedback - [`d538106`](https://github.com/cloudflare/vinext/commit/d53810647550a221e70645fb7c86f28ade78c7a3) perf: skip client reference preloading after first request ### 📊 Changes **3 files changed** (+100 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-ssr-entry.ts` (+20 -0) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+20 -0) 📝 `tests/app-router.test.ts` (+60 -0) </details> ### 📄 Description ## Summary Fixes #256. - First SSR request after `vinext start` returns 500 because client reference modules are loaded lazily via async `import()` in `@vitejs/plugin-rsc`'s `memoize()` cache - On the first request, `__vite_rsc_client_require__` returns an unresolved Promise. Without a `<Suspense>` boundary wrapping the root shell, React SSR rejects. Subsequent requests work because the cache is warm. - Added eager preloading of all client reference modules in the generated SSR entry (`app-ssr-entry.ts`) via `Promise.all` before `renderToReadableStream` runs - Guarded with `if (_clientReferences.default && globalThis.__vite_rsc_client_require__)` for safety ## Test plan - [x] Behavioral test: verifies memoize cache warming strategy works (cold cache → preload → warm cache) - [x] All 254 app-router tests pass - [x] Snapshot updates are mechanical (preloading block added to SSR entry) - [x] Typecheck and lint clean --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:24 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#662
No description provided.