sveltejs / sveltejs/kit

Remote functions: Prefetching prematurely tiggers redirect, disabling it subsequently

Open
#14,935 7 comments 1 reaction 0 assignees View on GitHub

@dummdidumm is already working on this.

Since Jul 9, 2026.

  • #16292 by @dummdidumm — open
router
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

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

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 component.svelte and fetch.remote.js reproduction, testing the link with prefetching enabled and disabled. Verify whether hovering invokes the remote function and consumes its redirect before a click; done means the redirect occurs only after the user activates the link, while the existing open pull request indicates work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.