-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Astro request.signal abort event not called for SSE #12867
Comments
Can tell us how to reproduce the issue and how this signal/SSE is supposed to work? |
In the reproduction here: https://stackblitz.com/edit/github-yi4swteg?file=src%2Fpages%2Fsse.ts However, when the user closes the tab, the |
This issue here is that Astro doesn't support AbortSignals at all. Astro creates the web Request object, mainly from Node IncomingMessage objects, which don't support abort signals natively so the generated requests have no signal passed to them. Support could in theory be added to |
Thank you! You're right. Using cancel works. Posting an example if anyone has the same use-case: export const GET: APIRoute = ({ request }) => {
const responseHeaders = {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
Connection: "keep-alive",
};
const stream = new ReadableStream({
start(controller) {
const encoder = new TextEncoder();
// Function to send messages to this client
const send = (message: string) => {
controller.enqueue(encoder.encode(`data: ${message}\n\n`));
};
// Send an initial message
send("Connected to SSE");
},
cancel() {
// Cleanup logic if needed
console.log("Client disconnected")
},
});
return new Response(stream, { headers: responseHeaders });
}; |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
While trying to implement SSE with node adapter in Astro, it seems the
abort
event is not triggered onrequest.signal
when the connection is closed.What's the expected result?
The following callback should be called when the client disconnects.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-yi4swteg?file=src%2Fpages%2Fsse.ts
Participation
The text was updated successfully, but these errors were encountered: