Closed mxswat closed 2 months ago
As a user, when I visit http://localhost:3000/ I expect to see "Game Name - 1" without seeing "Loading..." (This works)
For what it's worth, this also doesn't work for me. I can clearly see loading
here, too:
https://stackblitz.com/github/mxswat/react-query-hydration-bug
What I can see is that you create an unstable query client in the render function in the ClientProviders
, which throws away the cache. Please use the setup described in the docs:
Describe the bug
Using
prefetchQuery
to pre-fetch data does not work in a Next.js dynamic route.prefetchQuery
works fine in a Next.js Static route.Your minimal, reproducible example
https://codesandbox.io/p/devbox/github/mxswat/react-query-hydration-bug
Steps to reproduce
Install dependencies, and run the project using
npm run dev
Reproduction repo: https://github.com/mxswat/react-query-hydration-bug
(Attached is a video of this process below)
Expected behavior
As a user, when I visit http://localhost:3000/ I expect to see "Game Name - 1" without seeing "Loading..." (This works)
As a user, when I visit http://localhost:3000/masseffect3 I expect to see "Game Name - 1" without seeing "Loading..." (This does not work)
How often does this bug happen?
Every time
Screenshots or Videos
https://github.com/user-attachments/assets/d7264f88-2e06-445b-a77e-8ec6f68542ea
Platform
Operating System: Kubuntu 23.10 KDE Plasma Version: 5.27.8 KDE Frameworks Version: 5.110.0 Qt Version: 5.15.10 Kernel Version: 6.5.0-44-generic (64-bit) Graphics Platform: X11 Processors: 12 × Intel® Core™ i7-10750H CPU @ 2.60GHz Memory: 62.6 GiB of RAM Graphics Processor: NVIDIA GeForce RTX 2070 with Max-Q Design/PCIe/SSE2 Manufacturer: Micro-Star International Co., Ltd. Product Name: GS66 Stealth 10SF System Version: REV:1.0
Browser: Google Chrome Version 127.0.6533.99 (Official Build) (64-bit)
Tanstack Query adapter
react-query
TanStack Query version
5.55.4
TypeScript version
5.5.4
Additional context
I found another user with a similar issue, but I haven't heard back from them https://www.reddit.com/r/nextjs/comments/1f3ht0v/nextjs_ssr_with_reactquery_dynamic_routes_not/