[PR #515] [MERGED] fix: propagate middleware waitUntil to Workers execution context #636

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

📋 Pull Request Information

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

Base: mainHead: fix/app-router-mw-waituntil


📝 Commits (1)

  • 7d83101 fix: propagate middleware waitUntil promises to Workers execution context

📊 Changes

3 files changed (+24 additions, -2 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+3 -1)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+3 -1)
📝 tests/app-router.test.ts (+18 -0)

📄 Description

Summary

  • The App Router generated entry called mwFetchEvent.drainWaitUntil() but discarded the return value, so middleware background promises registered via event.waitUntil() were abandoned when the response was sent on Cloudflare Workers
  • Register the drained promise with the Workers execution context via _getRequestExecutionContext()?.waitUntil(), matching the pattern the Pages Router entry already uses (pages-server-entry.ts:208)

Test plan

  • Added test in app-router.test.ts verifying the generated code registers drainWaitUntil() with the execution context
  • Updated entry-templates.test.ts snapshot
  • CI: Vitest, Playwright E2E, typecheck, lint, format

🔄 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/515 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 3/13/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/app-router-mw-waituntil` --- ### 📝 Commits (1) - [`7d83101`](https://github.com/cloudflare/vinext/commit/7d83101baa80440ad955a46139f7161b8da051a8) fix: propagate middleware waitUntil promises to Workers execution context ### 📊 Changes **3 files changed** (+24 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+3 -1) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+3 -1) 📝 `tests/app-router.test.ts` (+18 -0) </details> ### 📄 Description ## Summary - The App Router generated entry called `mwFetchEvent.drainWaitUntil()` but discarded the return value, so middleware background promises registered via `event.waitUntil()` were abandoned when the response was sent on Cloudflare Workers - Register the drained promise with the Workers execution context via `_getRequestExecutionContext()?.waitUntil()`, matching the pattern the Pages Router entry already uses (`pages-server-entry.ts:208`) ## Test plan - [x] Added test in `app-router.test.ts` verifying the generated code registers `drainWaitUntil()` with the execution context - [x] Updated `entry-templates.test.ts` snapshot - [ ] CI: Vitest, Playwright E2E, typecheck, lint, format --- <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:14 +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#636
No description provided.