sveltejs / sveltejs/kit

Remote Functions: If query isn't used elsewhere, it gets re-fetched every time it's used in `.updates()`

Open
#14,299 0 comments 1 reaction 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 bug

If I have a form like this:

<form {...addTodo.enhance(async ({ data, submit }) => {
  await submit().updates(
    get_todos().withOverride((todos) => [...todos, { text: data.get('text') }])
  );
}}>

but for whatever reason get_todos() isn't currently being used elsewhere on the page (i.e. the todos component isn't mounted) the following issue happens:

  1. SvelteKit calls create_remote_function
  2. Cache miss - query_map doesn't contain get_todos()
  3. SvelteKit initializes get_todos() and makes a fetch request to the endpoint
  4. get_todos() gets cached
  5. get_todos() gets immediately removed from the cache, because there are no references to it
  6. Repeat steps 2-5, every time the form is submitted.
Reproduction

link

Logs

System Info
System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.1.0 
    @sveltejs/kit: ^2.22.0 => 2.36.1 
    @sveltejs/vite-plugin-svelte: ^6.0.0 => 6.1.3 
    svelte: ^5.25.0 => 5.38.2 
    vite: ^7.0.4 => 7.1.3
Severity

serious, but I can work around it

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 with the linked StackBlitz reproduction and confirm the repeated fetch during form submissions. Then trace create_remote_function, query_map, and the .updates() path to understand why an unreferenced get_todos() query is removed immediately; done means repeated submissions no longer re-fetch it unnecessarily.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.