Skip to content

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

@ottomated

Description

@ottomated

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions