[PR #685] [CLOSED] fix: exclude react-server-dom-webpack from rsc/ssr dep optimizer #769

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

📋 Pull Request Information

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

Base: mainHead: fix/rsc-streaming-dep-optimizer


📝 Commits (1)

  • 8cc6146 fix: exclude react-server-dom-webpack from rsc/ssr dep optimizer

📊 Changes

2 files changed (+33 additions, -2 deletions)

View changed files

📝 packages/vinext/src/index.ts (+16 -2)
📝 tests/app-router.test.ts (+17 -0)

📄 Description

Summary

  • Excludes react-server-dom-webpack from optimizeDeps in both the rsc and ssr environments, preventing dep optimizer re-runs from invalidating the Flight client module mid-request

Problem

When an App Router app has multiple routes that import different third-party packages, Vite's dep optimizer can re-run mid-request as it lazily discovers new user-land dependencies. A dep optimizer re-run re-bundles all pre-bundled modules, creating fresh module instances. In-flight RSC streams crash with chunk.reason.enqueueModel is not a function because Flight chunk objects created by the old ReactPromise constructor don't match functions from the new module instance.

Fix

Excluding react-server-dom-webpack from the dep optimizer means it's loaded through Vite's regular transform pipeline (which works correctly with noExternal: true) and is completely immune to re-optimisation invalidation. The exclude intentionally overrides the RSC plugin's include for this package (Vite exclude takes priority over include), ensuring the Flight protocol modules live outside the dep optimizer's lifecycle.

Both the rsc and ssr environments are covered — the RSC side produces the Flight stream (renderToReadableStream) and the SSR side consumes it (createFromReadableStream), so both need protection from module invalidation.

Closes #672

Test plan

  • New test verifies react-server-dom-webpack is in optimizeDeps.exclude for both rsc and ssr environments
  • Existing optimizeDeps.entries and optimizeDeps.include tests still pass
  • Full app-router test suite passes (272/272)

🔄 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/685 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/rsc-streaming-dep-optimizer` --- ### 📝 Commits (1) - [`8cc6146`](https://github.com/cloudflare/vinext/commit/8cc6146a1abd0caa1878a72b2356f284017b4221) fix: exclude react-server-dom-webpack from rsc/ssr dep optimizer ### 📊 Changes **2 files changed** (+33 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+16 -2) 📝 `tests/app-router.test.ts` (+17 -0) </details> ### 📄 Description ## Summary - Excludes `react-server-dom-webpack` from `optimizeDeps` in both the `rsc` and `ssr` environments, preventing dep optimizer re-runs from invalidating the Flight client module mid-request ## Problem When an App Router app has multiple routes that import different third-party packages, Vite's dep optimizer can re-run mid-request as it lazily discovers new user-land dependencies. A dep optimizer re-run re-bundles **all** pre-bundled modules, creating fresh module instances. In-flight RSC streams crash with `chunk.reason.enqueueModel is not a function` because Flight chunk objects created by the old `ReactPromise` constructor don't match functions from the new module instance. ## Fix Excluding `react-server-dom-webpack` from the dep optimizer means it's loaded through Vite's regular transform pipeline (which works correctly with `noExternal: true`) and is completely immune to re-optimisation invalidation. The `exclude` intentionally overrides the RSC plugin's `include` for this package (Vite `exclude` takes priority over `include`), ensuring the Flight protocol modules live outside the dep optimizer's lifecycle. Both the `rsc` and `ssr` environments are covered — the RSC side produces the Flight stream (`renderToReadableStream`) and the SSR side consumes it (`createFromReadableStream`), so both need protection from module invalidation. Closes #672 ## Test plan - [x] New test verifies `react-server-dom-webpack` is in `optimizeDeps.exclude` for both `rsc` and `ssr` environments - [x] Existing `optimizeDeps.entries` and `optimizeDeps.include` tests still pass - [x] Full app-router test suite passes (272/272) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:10:01 +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#769
No description provided.