You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<buttononClick={()=>{controller=newAbortController();fetch("/api/test",{method: "GET",signal: newAbortController().signal,}).then((response)=>{console.log("response",response);}).catch((error)=>{console.log("error",error);});}}>
Call
</button><buttononClick={()=>{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
Thanks for this issue and the thorough explanation, @tri2820
Imho, that's definitely something that's worth having a better DX around (ping @katywings for her 2cents).
If you have time, it would be great if you could add a reproduction to our /tests workspace.
You can start the PR with the failing test and then we can have a clear path moving forward.
Meanwhile, this workaround is worthy of the docs, so I'm pinging @LadyBluenotes in case she wants to create an issue there too :)
As soon as I can get my hands on trying the workaround, I can help writing the guide (but you're also ofc welcomed to do so if you want)
@tri2820 Thank you for bringing this up. I also think that having a better DX around abort sounds like a sensible addition 💯.
The first question coming to my mind is if event.nativeEvent.node.req.addListener('close', ...) is the proper way to do this from a nitro/h3 perspective. Maybe @pi0 can give us some insight about this 🙂. Touching event.node directly is usually not recommended by h3, so I wonder if there is some "more official" way to do this, or if it already is planned for a future update?
A similar question was asked in the Nitro Discussions under nitrojs/nitro#1541 but is unanswered 🙈.
Correction (this comment was wrong, reopening): this issue was filed against SolidStart 1.0, but the behavior below was verified on 2.0. SolidStart 1.0 and 2.0 have different request architectures (1.0 is vinxi + h3 v1; 2.0 is h3 v2 / srvx), so the 2.0 behavior does not show that 1.0 is fixed, and upgrading to 2.0 is not a resolution for this report. I should not have closed it. Leaving the 2.0 notes below for reference only.
On SolidStart 2.0 (h3 v2 / srvx), event.request is a standard Web Request whose signal aborts when the client disconnects, so the Web-standard API from the original example works without reaching into nativeEvent:
importtype{APIEvent}from"@solidjs/start/server";exportasyncfunctionGET(event: APIEvent){event.request.signal.addEventListener("abort",()=>{// fires when the client cancels the request});constupstream=awaitfetch("https://example.com/stream",{signal: event.request.signal,});returnnewResponse(upstream.body);}
Fixed on the 1.x line by #2340, released in @solidjs/start 1.4.0: on Node, event.request.signal now aborts when the client disconnects, so an API route can stop its work.
On 2.x, event.request.signal already aborts on client disconnect.
Activity
[-][Bug?]: Abort event does not fire on API route[/-][+][Bug?]: Abort event is not fired on API route[/+]tri2820 commentedon Feb 6, 2025
Update: After some digging I found out that we can listen to the close event on nativeEvent for this.
Nevertheless it would be good if
event.request.signal.addEventListener("abort", ...)is supportedatilafassina commentedon Feb 12, 2025
Thanks for this issue and the thorough explanation, @tri2820
Imho, that's definitely something that's worth having a better DX around (ping @katywings for her 2cents).
If you have time, it would be great if you could add a reproduction to our
/testsworkspace.You can start the PR with the failing test and then we can have a clear path moving forward.
Meanwhile, this workaround is worthy of the docs, so I'm pinging @LadyBluenotes in case she wants to create an issue there too :)
As soon as I can get my hands on trying the workaround, I can help writing the guide (but you're also ofc welcomed to do so if you want)
[-][Bug?]: Abort event is not fired on API route[/-][+][Feat]: Better DX for Abort events[/+]katywings commentedon Feb 12, 2025
@tri2820 Thank you for bringing this up. I also think that having a better DX around
abortsounds like a sensible addition 💯.The first question coming to my mind is if
event.nativeEvent.node.req.addListener('close', ...)is the proper way to do this from a nitro/h3 perspective. Maybe @pi0 can give us some insight about this 🙂. Touchingevent.nodedirectly is usually not recommended by h3, so I wonder if there is some "more official" way to do this, or if it already is planned for a future update?A similar question was asked in the Nitro Discussions under nitrojs/nitro#1541 but is unanswered 🙈.
lxsmnsyc commentedon Oct 13, 2026
Correction (this comment was wrong, reopening): this issue was filed against SolidStart 1.0, but the behavior below was verified on 2.0. SolidStart 1.0 and 2.0 have different request architectures (1.0 is vinxi + h3 v1; 2.0 is h3 v2 / srvx), so the 2.0 behavior does not show that 1.0 is fixed, and upgrading to 2.0 is not a resolution for this report. I should not have closed it. Leaving the 2.0 notes below for reference only.
On SolidStart 2.0 (h3 v2 / srvx),
event.requestis a standard WebRequestwhosesignalaborts when the client disconnects, so the Web-standard API from the original example works without reaching intonativeEvent:lxsmnsyc commentedon Oct 16, 2026
Fixed on the 1.x line by #2340, released in
@solidjs/start1.4.0: on Node,event.request.signalnow aborts when the client disconnects, so an API route can stop its work.On 2.x,
event.request.signalalready aborts on client disconnect.