Skip to content

React Query Cache Not Updating – Requires Manual Invalidation via useFocusEffect #9102

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

Closed
Moamen-Elgammal opened this issue May 3, 2025 · 1 comment

Comments

@Moamen-Elgammal
Copy link

Describe the bug

In my React Native app, the Portfolio screen displays a list of investment cards. Tapping on any card navigates to the InvestmentDetails screen, where a user can sell the investment using the useRequestInvestmentSell hook.

✅ Expected Behavior:
After submitting a sell request:

1- InvestmentDetails screen updates:

  • Shows a flag

  • Reflects the updated list of sell requests

2- Portfolio screen updates:

  • The sold investment card displays a flag indicating a pending sell request

To achieve this, I'm invalidating the following queries after submission:

  • INVESTMENT_SELL_REQUESTS (for the request list)

  • CUSTOMER_BANK_INVESTMENTS_DETAILS

  • CUSTOMER_BANK_INVESTMENTS (cards rendered in the Portfolio)

❌ Actual Behavior:
When navigating back to the Portfolio screen, the data does not update as expected.
The only workaround that currently works is manually calling invalidateQueries(CUSTOMER_BANK_INVESTMENTS) inside a useFocusEffect() hook on the Portfolio screen — but this feels like a hack and is not ideal for performance or code cleanliness. 😞

export const useRequestInvestmentSell = () => {
  const queryClient = useQueryClient()

  return useMutation(bankApi.requestInvestmentSell, {
    onSuccess: () => {
      queryClient.invalidateQueries(INVESTMENT_SELL_REQUESTS)
      queryClient.invalidateQueries(CUSTOMER_BANK_INVESTMENTS_DETAILS)
      queryClient.invalidateQueries(CUSTOMER_BANK_INVESTMENTS)
    },
  })
}

Your minimal, reproducible example

Steps to reproduce

Expected behavior

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

Tanstack Query adapter

None

TanStack Query version

TypeScript version

No response

Additional context

No response

@TkDodo
Copy link
Collaborator

TkDodo commented May 3, 2025

Thank you for filing this issue, but we need more information before looking into this.

Specifically, a minimal, standalone, runnable reproduction is needed - preferably with codesandbox or stackblitz. If your issue is TypeScript related, prefer a TypeScript playground.

We'll close this issue for now, but we'll certainly re-open it if there is a proper reproduction.

@TkDodo TkDodo closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants