sveltejs / sveltejs/kit

Abort signals for remote functions

Open
#14,502 20 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

As I understand it, when a remote function fires on the client, it's actually a fetch wrapper. I have a case where I have to call a remote whenever an input changes to search for something, as the user types. Now this is an obvious race condition, depending on how flaky the network decides to be, so I need to cancel a request as soon as the user changes the input, so that old requests don't mess up my result section.

Now I could just make a REST api and just manually fetch it, making it possible to use abort signals, but surely there should be some way for a remote function to be able to receive an abort signal. I've tried to search in the docs, but I couldn't find a way to do it, at least not an obvious one.

Describe the proposed solution

The most straightforward way is to have a config object that would contain some options for the underlying fetch call, one of which would be the abort signal. Otherwise make the remote functions abortable directly, somehow

Alternatives considered

Like I said, a classic api with a manual fetch in sveltekit, but now that we have remote function, they should technically replace all that nonsense.

Importance

nice to have

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the remote-function client entry point and the underlying fetch wrapper, then review the current documentation for remote functions. Determine how an abort signal could be exposed for requests triggered by changing input; done means an in-flight remote request can be cancelled without requiring a separate manual REST fetch.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.