abort `"user server"` function call

is it possible to abort a call to a "use server" function? behind the scenes they're just fetch()es right? if so is there some way to pass though an abort signal? thanks.
6 Replies
peerreynders
peerreynders•3w ago
https://discord.com/channels/722131463138705510/780502110772658196/1268618927387181168 Even if you go ahead an create an API Route and use an abort controller client side, you're still going to have to dig deep into the server platform's request to listen to the request closing (which happens right after an abort)
request.addListener('close', onClientClose);
request.addListener('close', onClientClose);
https://nodejs.org/api/http.html#http_event_close_3 to be able to catch the abort and then stop processing on the server side.
Samual 🦢
Samual 🦢OP•3w ago
I'm just using the self hosted node platform
peerreynders
peerreynders•3w ago
So you should have reliable access to node.req on APIEvent.nativeEvent
Event Object - h3
Event object carries an incoming request and context.
GitHub
solid-start/packages/start/src/server/types.ts at dbfc569e38e7c3494...
SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.
Samual 🦢
Samual 🦢OP•3w ago
so does this mean I can't use "use server"?
peerreynders
peerreynders•3w ago
Not if you want to use abort. RPC abstractions often don't expose a way to cancel and even abort is largely about the client side behaviour of fetch. Typically server code has to go out of its way to detect abort. In many cases the request just runs to completion and the finished response is ignored by the client.
MDN Web Docs
AbortController: abort() method - Web APIs | MDN
The abort() method of the AbortController interface aborts an asynchronous operation before it has completed. This is able to abort fetch requests, the consumption of any response bodies, or streams.
peerreynders
peerreynders•3w ago
FYI: To Seroval's credit you can successfully pass a promise from the client to the 'use server' section via action parameters. But it cannot be used to trigger an abort as the 'use server' section doesn't start running until the inbound promise has settled.

Did you find this page helpful?