Duplicates
Latest version
Current behavior 馃槸
When the request is aborted, the abort event is not fired within server API route.
Example server API route
import type { APIEvent } from "@solidjs/start/server";
export async function GET(event: APIEvent) {
event.request.signal.addEventListener("abort", () => {
console.log('abort detected')
})
let i = 0;
while (i < 20) {
console.log('looping', i++, event.request.signal.aborted)
await new Promise(resolve => setTimeout(resolve, 1000))
}
return new Response(null, { status: 200 })
}
Example browser triggers
<button
onClick={() => {
controller = new AbortController();
fetch("/api/test", {
method: "GET",
signal: new AbortController().signal,
})
.then((response) => {
console.log("response", response);
})
.catch((error) => {
console.log("error", error);
});
}}
>
Call
</button>
<button
onClick={() => {
console.log("controller", controller);
controller?.abort("I am aborting this request");
controller = undefined;
}}
>
Abort
</button>
Expected behavior 馃
When user cancel the request in browser, the abort event should be fired.
Steps to reproduce 馃暪
Steps:
- Create an API route
- Add abort listener inside the API route
- In the browser, fetch & abort
- Notice that the abort event is not fired inside the API route
Context 馃敠
I'm building an AI chat app that streams the token from the AI provider back to the user.
Currently when the user clicks aborting the request, the api route could not detect that and keep streaming from the AI provider, wasting token.
Not sure if related but Next.js used to have a similar issue vercel/next.js#48682
Your environment 馃寧
Linux denpa 6.12.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 18 Jan 2025 02:26:57 +0000 x86_64 GNU/Linux
bun --version
1.2.0
node --version
v23.4.0
"dependencies": {
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.15.0",
"@solidjs/start": "^1.0.11",
"solid-js": "^1.9.2",
"vinxi": "^0.4.3"
},
Duplicates
Latest version
Current behavior 馃槸
When the request is aborted, the abort event is not fired within server API route.
Example server API route
Example browser triggers
Expected behavior 馃
When user cancel the request in browser, the abort event should be fired.
Steps to reproduce 馃暪
Steps:
Context 馃敠
I'm building an AI chat app that streams the token from the AI provider back to the user.
Currently when the user clicks aborting the request, the api route could not detect that and keep streaming from the AI provider, wasting token.
Not sure if related but Next.js used to have a similar issue vercel/next.js#48682
Your environment 馃寧