sveltejs / sveltejs/kit

Remote Functions: timeouts and retries

Open
#14,942 1 comment 8 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

Derived from discussions:

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:

  1. Expose a per-function config to pass in an AbortController to manually time out requests, and a retry count to retry the request upon error, and a timeout number in milliseconds for how long to wait before the next retry.
  2. Expose a universal config for all functions to time out after a set number of milliseconds.
  3. Expose the underlying fetch for remote functions, or allow a passed-in fetch instance 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.