-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Labels
Description
EventSource.close
does not trigger onabort
Description
When using EventSource.close
on client side, request.signal.onabort
event is not triggered. This prevents proper handling of client disconnection in server-sent events (SSE).
According to the Cloudflare Workers changelog (2025-05-22 Changelog), this issue has been addressed in Cloudflare Workers, allowing proper handling of request cancellation. However, the same functionality does not work in OpenNext.
Code Example
Below is a sample code snippet demonstrating the issue:
import { sleep } from "@/lib/utils";
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
const stream = new ReadableStream({
async start(controller) {
request.signal.addEventListener("abort", () => {
controller.close();
});
while (!request.signal.aborted) {
controller.enqueue(
new TextEncoder().encode(
`data: ${JSON.stringify([1,2,3])}\n\n`,
),
);
await sleep(10 * 1000);
}
},
});
return new NextResponse(stream, {
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
Connection: "keep-alive",
},
});
}
@opennextjs/cloudflare version
1.1.0
Additional context
No response
Before submitting
- I have checked that there isn't already a similar feature request
- This is a single feature (not multiple features in one request)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
P2