[Sveltekit] prefetchQuery fails to cache if `url` object is accessed inside `layout.ts`
Describe the bug
This is kinda weird and oddly specific issue, in layout.ts, if I access the url object from the load() arguments, prefetchQuery fails to cache the result.
If I comment out the access statement, everything works fine.
Your minimal, reproducible example
https://codesandbox.io/p/github/maisonsmd/tanstack-sveltequery-prefetch-issue/main?import=true
Steps to reproduce
- Run project
- Check prefetchQuery (page.ts) function Case A. Hover on post list's items Case B. Click on a post
- Check network tab and Query Devtool for cache
Expected behavior
Case A
Expect: Only 1 API call needed per post, the response is cached Actual: the response is not cached, re-hovering on the same item fetches the API again.
Case B
Expect: Only 1 API call needed per post, the response is cached, clicking on the post does not result in additional API call. Actual: API is called 2 times per post as the result of failing to cache the previous call.
How often does this bug happen?
Every time
Screenshots or Videos
https://github.com/user-attachments/assets/7f5dd419-ab6e-4311-a313-986a6d3d16e8
Platform
OS: Windows 11 Pro 23H2 build 22631.4317 Browser: Microsoft Edge 129.0.2792.89 (64-bit)
Tanstack Query adapter
svelte-query
TanStack Query version
v5.59.13
TypeScript version
v5.3.3
Additional context
staleTime was set to 60 seconds.