-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maximum update depth exceeded #8677
Comments
I started getting this error after upgrading as well. I narrowed it down to version v5.66.4 introducing this behavior. |
Your test is very good, the problem was actually introduced in v5.66.4, I downgraded to v5.66.3 and the problem does not occur |
@juliusmarminge 5.66.4 was our hydration changes 😕 |
I think the following part of the logic added by #8383 in the PR might be causing some problems. This is because the code in the above link thinks that the new logic is new if the “promise.status” is different. But https://github.com/TanStack/query/pull/8383/files#diff-da66ebb93eacffd07c6ea6e697db57d6091050af95da336ea10e1aaedb07ef7cR86 is chasing a “promise”, so I think a new “promise” will be created each time. Wouldn't that cause “Maximum update depth exceeded” to be thrown because the new code thinks it's new every time? |
can anyone provide a minimal repro? I can look into this tonight but would help to have something simple to debug |
I did some validations in my personal project where the error occurs frequently, where if I export the Page as async and use await in prefetchQuery the problem does not occur:
|
yea but then you're no longer sending promises down so you're hitting completely different code paths with that - not really comparable |
I just want a state where it's failing on that PR I linked 😅 |
A simple way to reproduce it is to add an artificial delay to the “getApiV1ActivitiesOptions” function in your temporary repo PR(#8682 ) in the file “integrations/react-next-15/app/query.ts” ( |
(I used a translator) In React Query versions up to 5.66.3, only the dataUpdatedAt field was compared during hydration, which prevented this issue from occurring. However, starting with version 5.66.4, the dehydrated state now also includes pending queries because the shouldDehydrateQuery setting returns true even when query.state.status is 'pending'. This means that queries that have not yet completed are being included in the dehydrated state. During hydration, React Query internally attaches .then() and .catch() chains to these pending queries, effectively generating new Promise objects—especially when error redaction logic is applied. As a result, each render creates a new Promise instance, and the promise.status comparison logic interprets this as the query being “new” or updated. This triggers re-hydration, which in turn causes another render, leading to an infinite render loop. The problem is exacerbated in a development environment, particularly with Next.js' Hot Module Replacement (HMR) or Fast Refresh. When code changes while a query is still pending, the old pending Promise conflicts with the new code. This clash makes the infinite rendering issue much more likely to occur. In production builds, where a full page reload happens, this issue tends not to manifest as prominently. To reproduce the issue, use React Query version 5.66.4 or later with a configuration that includes pending queries in the dehydrated state (i.e., shouldDehydrateQuery returns true when query.state.status is 'pending'). Then, introduce an artificial delay in the getApiV1ActivitiesOptions function—for example, by adding This delay causes the query to remain pending. Next, while the query is still pending, change the code via HMR—for instance, by uncommenting and then commenting out the delay code. At this point, because the server-side (or RSC) prefetchQuery has run dehydrate while the query was still pending, the client’s HydrationBoundary receives a dehydrated state that includes the old pending Promise. The new code then interprets the Promise as “new” on every render, triggering an infinite render loop. |
oh you're changing the queryFn... that's annoying to test xd |
Yeah, the idea behind the reproduction was to intentionally reproduce the “promise” changing while “pending”. |
@juliusmarminge This is happening with failed queries for me. What I think is happening is that:
|
Closing was accidental. |
Describe the bug
I am getting the error "Maximum update depth exceeded"
Your minimal, reproducible example
https://stackblitz.com/~/github.com/yWilliamLima/test-error
Steps to reproduce
It usually occurs after a while of running whenever changing pages/routes
Expected behavior
Do not return this error
How often does this bug happen?
Sometimes
Screenshots or Videos
Platform
OS: Windows 11
Browser: Chrome
Node: 22.12.0
Tanstack Query adapter
None
TanStack Query version
5.66.5
TypeScript version
5.7.3
Additional context
The error in the console does not occur locally, only in stackblitz
Maybe because of this error in the stackblitz console it doesn't happen, because it gives a refresh
Because it is a minimal example, it takes a while to occur, but in my project it occurs frequently
The text was updated successfully, but these errors were encountered: