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
- Visit
/
- Click login and goto same page
- Click logout
- Click login and goto same page
This does the following:
- Visit a route that calls a
query requiring authentication
- 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.
- Log back in and navigate to the same route
- 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.
Describe the bug
When a
queryremote function throws aredirect(e.g. due to unauthenticated access), the redirect result is cached. After reauthenticating and revisiting the same route, the cache returnsundefinedwithout making a new network request — causing any$derived(await query(...))that consumes the result to yieldundefinedand crash on property access.Reproduction
https://github.com/hyunbinseo/svelte-kit-templates/tree/svelte-kit-16192
/This does the following:
queryrequiring authenticationquerythrows redirect, returningundefinedas the data.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 toundefinedfrom cache, and any property access on it throws:Note that
await_waterfallwarning 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
Severity
serious, but I can work around it
Additional Information
These are errors from our production Sentry:
It isn't identical to the MRE - it happens without reloading the same route.
When the user logs out, the awaited
queryresult in a component that should be unmounted is updated toundefinedbefore it is unmount. This was being captured. Hopefully resolving issue will fix that as well.