Skip to content

Remote functions: Prefetching prematurely tiggers redirect, disabling it subsequently #14935

@andreasputlitz

Description

@andreasputlitz

Describe the bug

It seems to me that prefetching is breaking the redirects I am using, when my user isn't logged in but should be.

Basically what happens is that when I hover over the link, it seems that the remote function is immediately triggered by the prefetch, and the redirect fires. You can see it in the address bar, which shows the address the redirect points to.

Thing is, I haven't clicked yet. When I now click on the link, the redirect is already "spent", and I end up on the page that I wanted to protect. Only if I now fully reload the page, I am redirected.

When I disable prefetching on that link, it works as intended.

Reproduction

component.svelte:

<script>
import { call  } from './fetch.remote'
</script>

await call()

fetch.remote.js:

export const call = query(async () =>
{
   redirect(307, '/some-other-route')
})

Logs

System Info

System:
    OS: Linux 6.6 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 10.78 GB / 15.48 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 24.8.0 - /home/andreas/.nvm/versions/node/v24.8.0/bin/node
    npm: 11.6.2 - /home/andreas/.nvm/versions/node/v24.8.0/bin/npm
  Browsers:
    Chrome: 141.0.7390.107
  npmPackages:
    @sveltejs/adapter-auto: ^7.0.0 => 7.0.0 
    @sveltejs/kit: ^2.47.1 => 2.48.5 
    @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1 
    svelte: ^5.41.0 => 5.43.7 
    vite: ^7.1.10 => 7.2.2

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions