fix(query-core): distinguish query keys differing only by a Date in partialMatchKey#10982
Open
YESHYUNGSEOK wants to merge 1 commit into
Open
fix(query-core): distinguish query keys differing only by a Date in partialMatchKey#10982YESHYUNGSEOK wants to merge 1 commit into
YESHYUNGSEOK wants to merge 1 commit into
Conversation
…artialMatchKey
Non-exact key matching traversed objects structurally, so two query keys
differing only by a `Date` value (e.g. `['report', { from: dateA }]` vs
`['report', { from: dateB }]`) were treated as equal even though `hashKey`
stores them as separate queries. This caused `invalidateQueries`,
`refetchQueries`, `removeQueries`, and `cancelQueries` (which default to
non-exact matching) to match unrelated sibling queries.
`partialMatchKey` now compares non-plain objects the same way `hashKey`
serializes them, keeping non-exact matching consistent with cache identity.
Co-authored-by: Claude <noreply@anthropic.com>
Contributor
📝 WalkthroughWalkthroughpartialMatchKey now uses recursive matching only for plain arrays and plain objects, and hash-based comparison for other object values. New tests cover differing and equal Date values plus hash-equivalent Map values. A changeset records the query-core fix. ChangespartialMatchKey matching update
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Non-exact query-key matching (
partialMatchKey) traverses objects structurally viaObject.keys(b).every(...). For values whose data lives in internal slots rather than own-enumerable keys,Object.keys()is[], so the comparison is vacuouslytrue. This makes two keys that differ only by aDatecompare as equal — even thoughhashKeyserializes Dates to distinct ISO strings and therefore stores them as separate cache entries.As a result, non-exact operations (
invalidateQueries,refetchQueries,removeQueries,cancelQueries, andcreatePersistermatching) over-match unrelated sibling queries:Fix
partialMatchKeynow only traverses plain objects/arrays structurally; any other object (e.g.Date) is compared the same wayhashKeyserializes it, keeping non-exact matching consistent with cache identity:Datekeys that differ are no longer matched (the bug).Map/Set/RegExpkeep matching, becausehashKeyalso serializes them to{}— they already share a cache entry, so behavior there is unchanged and consistent.Tests
Added regression tests to the
partialMatchKeysuite: distinctDatevalues must not match, equalDatevalues must match, andMapkeys that hash equally keep matching.✅ Checklist
pnpm run test:pr.🚀 Release Impact
patchfor@tanstack/query-core).🤖 Generated with Claude Code
Summary by CodeRabbit
Datevalues no longer incorrectly match.Map, when their serialized values are the same.Dateand other hash-equivalent object matching behavior.