sveltejs / sveltejs/kit

`query` caches redirect response, returning `undefined` on next visit

Open
#16,192 5 comments 0 reactions 1 assignee View on GitHub

@elliott-with-the-longest-name-on-github is already working on this.

Since Jul 6, 2026.

  • #16226 by @elliott-with-the-longest-name-on-github — closed without merging
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

When a query remote function throws a redirect (e.g. due to unauthenticated access), the redirect result is cached. After reauthenticating and revisiting the same route, the cache returns undefined without making a new network request — causing any $derived(await query(...)) that consumes the result to yield undefined and crash on property access.

Reproduction

https://github.com/hyunbinseo/svelte-kit-templates/tree/svelte-kit-16192

  1. Visit /
  2. Click login and goto same page
  3. Click logout
  4. Click login and goto same page

This does the following:

  1. Visit a route that calls a query requiring authentication
  2. Log out — all queries are invalidated due to form submission, the query re-runs, but the session cookie is now gone. query throws redirect, returning undefined as the data.
  3. Log back in and navigate to the same route
  4. The query is NOT re-fetched — the cached response is returned immediately

The cached response for the post-logout re-fetch is:

{"type":"result","data":"[{\"redirect\":1},\"/login\"]"}

On re-login, no network request is made for the query.

The $derived(await query(...)) resolves to undefined from cache, and any property access on it throws:

Uncaught TypeError: Cannot read properties of undefined (reading 'name')

Note that await_waterfall warning is only fired when the runtime error occurs. See the following logs:

Logs
+layout.svelte:12
{id: 'static', name: 'Item static'}

+layout.svelte:12
undefined

Component.svelte:12
[svelte] await_waterfall / An async derived, `rawSubItem` (src/routes/[id]/Component.svelte:12:20) was not read immediately after it resolved.

+layout.svelte:15
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'name')
System Info
System:
  OS: Windows 11 10.0.26200
  CPU: (8) x64 Intel(R) Core(TM) Ultra 7 258V
  Memory: 5.42 GB / 31.48 GB
Binaries:
  Node: 24.18.0 - C:\Users\hyunb\AppData\Local\fnm_multishells\28632_1782650315550\node.EXE
  npm: 11.16.0 - C:\Users\hyunb\AppData\Local\fnm_multishells\28632_1782650315550\npm.CMD
  pnpm: 11.5.1 - C:\Users\hyunb\AppData\Local\fnm_multishells\28632_1782650315550\pnpm.CMD
  Deno: 2.4.0 - C:\Users\hyunb\.deno\bin\deno.EXE
Browsers:
  Chrome: 149.0.7827.199
  Edge: Chromium (149.0.4022.80)
  Firefox: 152.0.1 - C:\Program Files\Mozilla Firefox\firefox.exe
npmPackages:
  @sveltejs/adapter-auto: ^7.0.1 => 7.0.1
  @sveltejs/kit: ^2.68.0 => 2.68.0
  @sveltejs/vite-plugin-svelte: ^7.1.2 => 7.1.2
  svelte: ^5.56.4 => 5.56.4
  vite: ^8.1.0 => 8.1.0
Severity

serious, but I can work around it

Additional Information

These are errors from our production Sentry:

Cannot read properties of undefined (reading 'name')
Cannot read properties of undefined (reading 'address')

It isn't identical to the MRE - it happens without reloading the same route.

When the user logs out, the awaited query result in a component that should be unmounted is updated to undefined before it is unmount. This was being captured. Hopefully resolving issue will fix that as well.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.