Skip to content
Source
Sign inSign up
TanStack/query

Query displays old data when memoized select function is used #3139

Send to my agent
Closedmgrunberg(GitHub profile, opens in a new tab) opened this issue 5 comments

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

  1. Wait 2 seconds until the page shows Data: selected 2
  2. Click inc button. Page changes and shows Data: selected 3
  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

  1. TkDodo added labelsbug

  2. 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

  3. @TkDodo looks good to me. Thanks for the quick response :smile:

  4. TkDodo closed this

  5. :tada: This issue has been resolved in version 3.34.7 :tada:

    The release is available on:

    Your semantic-release bot :package::rocket:

  6. tannerlinsley added labelsreleased

  7. :tada: This issue has been resolved in version 4.0.0-alpha.6 :tada:

    The release is available on:

    Your semantic-release bot :package::rocket:

  8. tannerlinsley added labelsreleased on @alpha

Sign in to join this conversation.