[PR #343] [MERGED] fix: don't intercept requests in connect handler when cloudflare plugin is present #494

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

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/343
Author: @james-elicx
Created: 3/8/2026
Status: Merged
Merged: 3/8/2026
Merged by: @james-elicx

Base: mainHead: j-branch-3


📝 Commits (2)

  • 783fe1e test: assert App Router wins over Pages Router connect handler with cloudflare plugin
  • e1ccd61 update req.url with url

📊 Changes

2 files changed (+83 additions, -0 deletions)

View changed files

📝 packages/vinext/src/index.ts (+30 -0)
tests/e2e/cloudflare-dev/pages-router.spec.ts (+53 -0)

📄 Description

When @cloudflare/vite-plugin is loaded alongside vinext, the connect handler in index.ts was still attempting to handle Pages Router requests directly — running middleware, matching routes, calling createSSRHandler(), and invoking ssrLoadModule to render pages in the host Node.js process.

This crashes with:

TypeError: Cannot read properties of undefined (reading 'outsideEmitter')

because SSRCompatModuleRunner requires a hot channel that doesn't exist in the host process when the Cloudflare plugin is present. All rendering — both App Router and Pages Router — is supposed to go through the Cloudflare plugin's Worker entry (miniflare), not the host connect handler.

The fix: after running middleware (the only thing that legitimately belongs in the host connect handler), call next() immediately when hasCloudflarePlugin is true. This hands off to the Cloudflare plugin's connect handler, which dispatches the request to miniflare. Any middleware rewrite is written back to req.url first so miniflare sees the correct path.

The pages/index.tsx stub in app-router-cloudflare and the cloudflare-dev Playwright project exist specifically to assert this — if the connect handler intercepts /, pages/index.tsx renders instead of app/page.tsx, and the test fails.


🔄 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/343 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 3/8/2026 **Status:** ✅ Merged **Merged:** 3/8/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `j-branch-3` --- ### 📝 Commits (2) - [`783fe1e`](https://github.com/cloudflare/vinext/commit/783fe1ec964d97742bf78832816eac0b86873d30) test: assert App Router wins over Pages Router connect handler with cloudflare plugin - [`e1ccd61`](https://github.com/cloudflare/vinext/commit/e1ccd617cfbe9518ed098f24443221afd777c557) update req.url with url ### 📊 Changes **2 files changed** (+83 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+30 -0) ➕ `tests/e2e/cloudflare-dev/pages-router.spec.ts` (+53 -0) </details> ### 📄 Description When `@cloudflare/vite-plugin` is loaded alongside vinext, the connect handler in `index.ts` was still attempting to handle Pages Router requests directly — running middleware, matching routes, calling `createSSRHandler()`, and invoking `ssrLoadModule` to render pages in the host Node.js process. This crashes with: ``` TypeError: Cannot read properties of undefined (reading 'outsideEmitter') ``` because `SSRCompatModuleRunner` requires a hot channel that doesn't exist in the host process when the Cloudflare plugin is present. All rendering — both App Router and Pages Router — is supposed to go through the Cloudflare plugin's Worker entry (miniflare), not the host connect handler. **The fix:** after running middleware (the only thing that legitimately belongs in the host connect handler), call `next()` immediately when `hasCloudflarePlugin` is true. This hands off to the Cloudflare plugin's connect handler, which dispatches the request to miniflare. Any middleware rewrite is written back to `req.url` first so miniflare sees the correct path. The `pages/index.tsx` stub in `app-router-cloudflare` and the `cloudflare-dev` Playwright project exist specifically to assert this — if the connect handler intercepts `/`, `pages/index.tsx` renders instead of `app/page.tsx`, and the test fails. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:23 +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#494
No description provided.