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

[BUG] queryOptions.select runs multiple times #6713

Open
jpenna opened this issue Mar 19, 2025 · 3 comments
Open

[BUG] queryOptions.select runs multiple times #6713

jpenna opened this issue Mar 19, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@jpenna
Copy link

jpenna commented Mar 19, 2025

Describe the bug

I'm using GraphQL and I'm changing the data with the React Query's select middleware. It should run only once per request, but it is running multiple times.

Steps To Reproduce

  1. Use the useList hook
  2. Add queryOptions.select: (data) => { console.log('select'); return data }
  3. See "select" is logged multiple times

Replication CodeSandbox: https://codesandbox.io/p/sandbox/react-query-5-forked-hh85pv

Expected behavior

It should run only once. In React Query's documentation, they say to memoize the select function: https://tanstack.com/query/latest/docs/framework/react/guides/render-optimizations#memoization

useList is changing the function reference on every render.

Packages

  • "@refinedev/core": "^4.54.0",

Additional Context

Possible fix: pass the select function inside a useCallback to useList's useQuery

@jpenna jpenna added the bug Something isn't working label Mar 19, 2025
@alicanerdurmaz
Copy link
Member

Hello @jpenna, Thanks for the detailed explanation.

I believe your suggested fix will solve the problem, Do you want to work on this?

@jpenna
Copy link
Author

jpenna commented Mar 24, 2025

Hey @alicanerdurmaz , I was going to send it, but the contribution process seemed to require more time than I can afford at the moment...

@alicanerdurmaz
Copy link
Member

Hey @alicanerdurmaz , I was going to send it, but the contribution process seemed to require more time than I can afford at the moment...

We release a new version in the first week of every month. If you're not available, I can open a PR, or maybe someone else can do it. No problem, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants