-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(queriesObserver): fix getOptimisticResult, order of returned observers #3052
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 getOptimisticResult, order of returned observers #3052
Conversation
Fix queriesObserver to call getOptimisticResult as before. This was a bug introduced in PR TanStack#2866
Sort returned observer entries to match the order of queries. Previously, with keepPreviousData: true, the repurposed observers would be returned last, potentially in different order than the queries.
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tanstack/react-query/8z5ZSrBPCevLtaoNZ8pKjjyc8MDZ |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit be6cb12:
|
Codecov Report
@@ Coverage Diff @@
## master #3052 +/- ##
=======================================
Coverage 96.45% 96.46%
=======================================
Files 45 45
Lines 2259 2261 +2
Branches 641 641
=======================================
+ Hits 2179 2181 +2
Misses 77 77
Partials 3 3
Continue to review full report at Codecov.
|
I actually did notice this in the other PR, but then somehow thought it didn't matter 🙈 |
|
@all-contributors add @jvuoti for code |
|
I've put up a pull request to add @jvuoti! 🎉 |
|
🎉 This PR is included in version 4.0.0-alpha.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 3.34.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fix for
queriesObserver.getOptimisticResultto correctly callgetOptimisticResulton the observers.This was an issue I introduced in PR #2866. There I had needed to tweak two original tests, which now in hindsight were off due to this issue. I now reverted those tests back to the original form.
Now testing the issue, I also noticed a small issue with the order of the observers returned by
findMatchingObservers: withkeepPreviousData: true, any repurposed observers would be returned last, potentially in different order than the given queries.The fix is just to sort the observer entries by the order of the queries before returning them. This also gets rid of an extra render at least in some tests. As this was a rather small fix, I included the commit for that fix here, but I can also put it in a separate PR if that would be cleaner.