-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(QueriesObserver): fix improper sorting in QueriesObserver's #find… #8351
Conversation
…MatchingObservers method This commit fixes a bug in the QueriesObserver's #findMatchingObservers. The bug is present when there are duplicate unsorted queries, for example, ['A', 'B', 'A']. The bug results in #findMatchingObservers to return the queries in sorted order, or ['A', 'A', 'B'], which results in a mismatch between Array<QueryObserverOptions> and Array<QueryObserverMatch>. This bug was introduced in TanStack@5499577
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 6d34f02. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the same key inside useQueries
multiple times is not something that we support. I’m sure we have a discussion / issue about this where we mentioned this. Maybe documenting this is the better way to go.
oh, there should even be a warning in development mode. are you not seeing that ? |
Not supporting same key is fine, but this bug was introduced by this recent change 5499577 Prior to this change, duplicate keys wouldn't result in a mismatch between input and output. |
but “duplicate keys” and “same keys” are the same thing? Our warning even says that the behaviour is potentially unexpected. |
I am seeing the warning, but I think we should still fix it to return the correct order, even in spite of duplicate queries. In other words, after the bug was introduced, In that commit, we refactored things to efficiently loop over |
Yes, the warning does warn against having duplicate/same queries, but in the event that a caller has duplicate/same queries, wouldn't we want to return the correct answer to the best of our abilities? The library used to, but only recently started to return the wrong value after this change. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8351 +/- ##
===========================================
+ Coverage 45.97% 62.90% +16.93%
===========================================
Files 200 136 -64
Lines 7509 4799 -2710
Branches 1718 1348 -370
===========================================
- Hits 3452 3019 -433
+ Misses 3680 1540 -2140
+ Partials 377 240 -137 |
…MatchingObservers method
This commit fixes a bug in the QueriesObserver's #findMatchingObservers. The bug is present when there are duplicate unsorted queries, for example, ['A', 'B', 'A']. The bug results in #findMatchingObservers to return the queries in sorted order, or ['A', 'A', 'B'], which results in a mismatch between Array and Array. This bug was introduced in 5499577