Query cache persistence and Next.js 404 page #8517
-
Hi, I want to use TanStack Query with Next.js to cache client-side API requests and utilize scroll restoration. Due to other requirements, I want to resort to client-side fetching as much as possible. However, I noticed that the query cache resets when I hit a 404 in Next.js. Is this a Next.js issue/limitation? Is there a way to persist the query cache in this situation? Example
Here, you can see that scroll restoration works when you navigate with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
clicking on the |
Beta Was this translation helpful? Give feedback.
-
From what I found, if you call https://nextjs.org/docs/app/api-reference/file-conventions/not-found There seem to be workarounds like handling all Not Found pages with the catch-all segment, but this makes all Not Found instances into HTTP 200, which feels inconsistent with conventions. So, the current behavior, where the query cache is persistent while programmatically calling |
Beta Was this translation helpful? Give feedback.
clicking on the
Non-existent Page
link results in a full page reload, which of course clears the cache. I don’t know if this is standard nextJs behaviour, or if opting into a custom 404 page will make this better.