[PR #1066] fix: prevent React externalization leak in App Router SSR #1063

Open
opened 2026-05-06 13:11:48 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1066
Author: @StringerBell69
Created: 5/5/2026
Status: 🔄 Open

Base: mainHead: fix/react-dedupe-ssr-external


📝 Commits (2)

  • d6b1f50 fix: prevent React externalization leak in App Router SSR
  • b788844 fix: create dedicated pages_ssr env for Pages Router dev

📊 Changes

3 files changed (+114 additions, -1 deletions)

View changed files

📝 packages/vinext/src/index.ts (+30 -1)
tests/react-dedupe.test.ts (+82 -0)
📝 vite.config.ts (+2 -0)

📄 Description

Resolves #848

The Bug
When both top-level ssr.external and per-environment environments.ssr are set, Vite merges the top-level config into the environment. This caused React packages from ssr.external to leak into the App Router SSR environment's external list, making Node.js resolve React from vinext's package scope instead of the project root.

This bypassed resolve.dedupe and produced dual React instances in split-install topologies (npm link / bun link), resulting in 'Invalid hook call' errors during SSR.

The Fix
Only include React in top-level ssr.external when App Router is NOT active. When App Router is active, per-environment configs already define the correct external lists without React.

Testing
Adds a regression test verifying:

  • App Router: React not in top-level ssr.external
  • Pages Router: React still externalized (CJS compat)
  • resolve.dedupe always includes React packages

🔄 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/1066 **Author:** [@StringerBell69](https://github.com/StringerBell69) **Created:** 5/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/react-dedupe-ssr-external` --- ### 📝 Commits (2) - [`d6b1f50`](https://github.com/cloudflare/vinext/commit/d6b1f507b03c6015db38643e634ce0352e07fe3d) fix: prevent React externalization leak in App Router SSR - [`b788844`](https://github.com/cloudflare/vinext/commit/b78884424c159fbf19e87959bc4202ec881e3f3c) fix: create dedicated pages_ssr env for Pages Router dev ### 📊 Changes **3 files changed** (+114 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+30 -1) ➕ `tests/react-dedupe.test.ts` (+82 -0) 📝 `vite.config.ts` (+2 -0) </details> ### 📄 Description Resolves #848 **The Bug** When both top-level `ssr.external` and per-environment `environments.ssr` are set, Vite merges the top-level config into the environment. This caused React packages from `ssr.external` to leak into the App Router SSR environment's external list, making Node.js resolve React from vinext's package scope instead of the project root. This bypassed `resolve.dedupe` and produced dual React instances in split-install topologies (`npm link` / `bun link`), resulting in 'Invalid hook call' errors during SSR. **The Fix** Only include React in top-level `ssr.external` when App Router is NOT active. When App Router is active, per-environment configs already define the correct external lists without React. **Testing** Adds a regression test verifying: - App Router: React not in top-level `ssr.external` - Pages Router: React still externalized (CJS compat) - `resolve.dedupe` always includes React packages --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#1063
No description provided.