Remote Functions: timeouts and retries
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
Derived from discussions:
- https://github.com/sveltejs/kit/discussions/13897#discussioncomment-13673002
- https://github.com/sveltejs/kit/discussions/13897#discussioncomment-13594549
Sometimes users on a slow or distant connection cannot complete a request roundtrip from the browser to the server, and in some cases a retry would save the user time while designers can provide feedback for the delayed response.
Or, a user may become briefly offline and the outgoing remote functions need a way to replay once the user is online again.
Describe the proposed solution
A combination of solutions could be helpful:
- Expose a per-function config to pass in an
AbortControllerto manually time out requests, and aretrycount to retry the request upon error, and atimeoutnumber in milliseconds for how long to wait before the next retry. - Expose a universal config for all functions to time out after a set number of milliseconds.
- Expose the underlying
fetchfor remote functions, or allow a passed-infetchinstance to support preconfigured options.
Alternatives considered
Handle errors and retries in userland without convenience options:
<script>
import { getItems } from './data.remote'
// in lieu of `getItems({ retries: 2 })` or equivalent
let getItemsRetryCount = $state(2)
$effect(() => {
// TODO: this is flawed logic, but the intent is to call this effect
// whenever a remote function completes
if (!getItems().error || getItemsRetryCount <= 0) return
getItems().refresh()
getItemsRetryCount--
})
</script>
<svelte:boundary>
<!-- pending and error snippets for initial data representations -->
<!-- if I had them! -->
{#if getItems().error && getItemsRetryCount > 0}
Retrying...
{:else if getItems().error}
Server error, please try again in a few minutes. <button onclick={() => getItems().refresh()}>Try again</button>
{:else if getItems().loading}
Loading...
{:else if getItems().ready}
<ul>
{#each getItems().current as item}
<li>{item}</li>
{/each}
</ul>
{/if}
</svelte:boundary.
Importance
would make my life easier
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the two linked discussions and the remote-functions behavior described in this issue. Determine whether timeout, retry, AbortController, offline replay, and custom fetch support can share a coherent configuration model. Done means the scope, API behavior, and acceptance criteria are settled; no implementation files or tests are named here.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100