Describe the bug
When using svelte-query with sveltekit, createQuery executes on the server. This causes any client-specific APIs, such as a relative fetch or window access, to throw an error. Furthermore, since async SSR must be done in the load function in sveltekit, the result of queryFn is dropped.
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/lucid-architecture-sqwk6e?file=%2Fsrc%2Froutes%2F%2Bpage.svelte
Steps to reproduce
- Open the dev logs
- Reload the page
- Observe the error being thrown on the server
- Observe that even though the error is caught, and the string
'error' is returned, the client renders undefined until it finishes fetching
Expected behavior
I expect queryFn only to be called on the client but it is called on the server.
How often does this bug happen?
Every time
Platform
- OS: Linux
- Browser: Firefox
TanStack Query version
4.22.1
Additional context
Workaround is to add
import { browser } from '$app/environment';
// ...
queryFn: () => {
if (!browser) return null;
// ...
}
Describe the bug
When using svelte-query with sveltekit,
createQueryexecutes on the server. This causes any client-specific APIs, such as a relative fetch orwindowaccess, to throw an error. Furthermore, since async SSR must be done in theloadfunction in sveltekit, the result ofqueryFnis dropped.Your minimal, reproducible example
https://codesandbox.io/p/sandbox/lucid-architecture-sqwk6e?file=%2Fsrc%2Froutes%2F%2Bpage.svelte
Steps to reproduce
'error'is returned, the client rendersundefineduntil it finishes fetchingExpected behavior
I expect
queryFnonly to be called on the client but it is called on the server.How often does this bug happen?
Every time
Platform
TanStack Query version
4.22.1
Additional context
Workaround is to add