Skip to content
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): memoized select functions should not return outdated values #3140

Merged
merged 1 commit into from Dec 28, 2021

Conversation

TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Dec 28, 2021

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 #3139

…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
@vercel
Copy link

vercel bot commented Dec 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tanstack/react-query/BManugcg3QoE79N4YwKSowuFEZ38
✅ Preview: https://react-query-git-fork-tkdodo-feature-3139-tanstack.vercel.app

@codesandbox-ci
Copy link

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 d372e06:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration
quizzical-leaf-2tjb8 Issue #3139

@codecov
Copy link

codecov bot commented Dec 28, 2021

Codecov Report

Merging #3140 (d372e06) into master (b977cf4) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3140   +/-   ##
=======================================
  Coverage   96.47%   96.47%           
=======================================
  Files          45       45           
  Lines        2270     2270           
  Branches      639      639           
=======================================
  Hits         2190     2190           
  Misses         77       77           
  Partials        3        3           
Impacted Files Coverage Δ
src/core/queryObserver.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b977cf4...d372e06. Read the comment docs.

@TkDodo TkDodo merged commit d7faf86 into TanStack:master Dec 28, 2021
@TkDodo TkDodo deleted the feature/3139 branch December 28, 2021 17:34
@tannerlinsley
Copy link
Collaborator

🎉 This PR is included in version 3.34.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tannerlinsley
Copy link
Collaborator

🎉 This PR is included in version 4.0.0-alpha.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query displays old data when memoized select function is used
2 participants