You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recomputing a cached selector error changes errorUpdatedAt, which can cause an infinite render loop through React's external-store snapshot checks. Reuse the previous timestamp when the error reference is unchanged.
The regression test fails on main because the timestamp changes after the clock advances. With this fix, all 85 observer tests pass through Nx using existing local dependencies. Formatting checks pass. The full pnpm run test:pr command has not run.
QueryObserver now retains the previous error timestamp when a selector produces the same error again. A regression test checks that the result object remains unchanged after a timer advance and updateResult().
Changes: QueryObserver selector errors
Layer / File(s)
Summary
Preserve timestamps for repeated selector errors packages/query-core/src/queryObserver.ts, packages/query-core/src/__tests__/queryObserver.test.tsx, .changeset/stable-selector-error-timestamp.md
When a selector error matches the previous error, QueryObserver retains its timestamp; otherwise, it uses the current time. The regression test checks the cached initial-data case, and the changeset marks a patch release.
TanStack/query#12533: Also addresses issue #12532 and compares successive thrown errors.
TanStack/query#12539: Also addresses issue #12532 and compares successive errors by their properties.
Suggested reviewers:sukvvon
Merge Risk: Low · up to b6bed
The fix stabilizes repeated selector errors, but switching queries can retain an older failure timestamp when both selectors throw the same error object. This narrow regression warrants owner awareness or a focused correction.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
Fixes #12532.
Recomputing a cached selector error changes
errorUpdatedAt, which can cause an infinite render loop through React's external-store snapshot checks. Reuse the previous timestamp when the error reference is unchanged.The regression test fails on
mainbecause the timestamp changes after the clock advances. With this fix, all 85 observer tests pass through Nx using existing local dependencies. Formatting checks pass. The fullpnpm run test:prcommand has not run.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit