-
-
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(queryObserver): make sure that memoized select function only runs once per input #3098
Conversation
… once per input we compute the result optimistically, and then one more time when calling setOptions. Both times run the select function because only setOptions will update the previous result and previous options. storing the "previous" selectFn separately on the observer whenever it was invoked (independent of the fact from where it was called) side-steps the issue
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tanstack/react-query/9arZ9xZC3Spo2XQVqftMCYgDwByj |
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 caef29c:
|
Codecov Report
@@ Coverage Diff @@
## master #3098 +/- ##
=======================================
Coverage 96.47% 96.47%
=======================================
Files 45 45
Lines 2269 2270 +1
Branches 639 639
=======================================
+ Hits 2189 2190 +1
Misses 77 77
Partials 3 3
Continue to review full report at Codecov.
|
@chrislacey89 FYI |
@TkDodo works like a charm. Good work! |
🎉 This PR is included in version 3.34.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 4.0.0-alpha.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
…ted values not all runs to createResult are saved on `this.currentResult` (optimistically created updates do not - we just create the result again later). With the fix from TanStack#3098, we made sure that memoized select does not run again in those cases by storing every run. However, that now means that we cannot rely on `prevResult.data` because it might still contain outdated data. The solution is to store a pair of previous selectFn + data and return the exact data that was computed from the previous select fn if we get the exact same function passed
…ted values (#3140) not all runs to createResult are saved on `this.currentResult` (optimistically created updates do not - we just create the result again later). With the fix from #3098, we made sure that memoized select does not run again in those cases by storing every run. However, that now means that we cannot rely on `prevResult.data` because it might still contain outdated data. The solution is to store a pair of previous selectFn + data and return the exact data that was computed from the previous select fn if we get the exact same function passed
closes #3095
we compute the result optimistically, and then one more time when calling setOptions. Both times run the select function because only setOptions will update the previous result and previous options. storing the "previous" selectFn separately on the observer whenever it was invoked (independent of the fact from where it was called) side-steps the issue