Describe the bug#
I'm using memoized select functions on my queries (following TkDodo's Blog recommendations on this topic).
After upgrading to react-query 3.34.6 from 3.34.0 I notice that the query recomputes the result each time the select function changes but it returns an old result if the component containing the query re-renders due to, for example, user interaction.
Your Example Website or App#
https://codesandbox.io/s/blazing-dawn-ejcb0?file=/src/index.js
Steps to reproduce#
- Wait 2 seconds until the page shows
Data: selected 2
- Click
inc button. Page changes and shows Data: selected 3
- Click
refresh button. Page changes back to Data: selected 2
You can repeat steps 2 and 3 as many times you want
Expected behavior#
Page should show Data: selected 3
How often does this bug happen?#
Every time
Screenshots or Videos#
https://user-images.githubusercontent.com/1459326/147570074-a6f6a1bf-2472-42c7-9bec-bdbcef350150.mp4
Platform#
- OS: Linux
- Browser: Chrome
- Version: 96.0.4664.110
Additional context#
I believe the issue was introduced by https://github.com/tannerlinsley/react-query/pull/3098/files but I don't have enough knowledge to be sure or propose a fix
yep, I definitely broke that, sorry :/ caching is hard. Thank you for the reproduction - I will create a test case out of the issue and take a look into fixing this