Skip to content

fix(mobile): cleaning query cache when network changes [PERA-3678]#132

Merged
fmsouza merged 5 commits intomainfrom
fmsouza/pera-3678
Feb 25, 2026
Merged

fix(mobile): cleaning query cache when network changes [PERA-3678]#132
fmsouza merged 5 commits intomainfrom
fmsouza/pera-3678

Conversation

@fmsouza
Copy link
Contributor

@fmsouza fmsouza commented Feb 24, 2026

Pull Request Template

Description

  • Add the network state to the query cache to make sure cache will not be reused once the network mode changes, which should cause the tokens to be presented correctly on the different network states (mainnet, testnet)

Related Issues

Checklist

  • Have you tested your changes locally?
  • Have you reviewed the code for any potential issues?
  • Have you documented any necessary changes in the project's documentation?
  • Have you added any necessary tests for your changes?
  • Have you updated any relevant dependencies?

Additional Notes

  • Add any additional notes or comments that may be helpful for reviewers.

@fmsouza fmsouza requested a review from wjbeau February 24, 2026 16:52
@fmsouza fmsouza self-assigned this Feb 24, 2026
Comment on lines 33 to 46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be the actual problem with the account assets. We're storing a single assetIDs list, but the assets we need are different on testnet and mainnet I guess?

I don't know if this whole concept works tbh. It might be better to just rely on react-query caching or something. The idea here was to keep track of which assets the user is interested in and just fetch those once and keep them up to date but i don't know if that really works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wjbeau I did a very thorough review on the implementation after your question and changed the implementation in many points

  • Remove zustand, rely on react query alone
  • Make sure it won't break app performance
  • Make sure the assets will be updated whenever the network changes
  • Make sure the transactions history will also be updated as the network changes

Comment on lines 41 to 48
const idsRef = useRef(ids)
if (
ids.length !== idsRef.current.length ||
!ids.every((id, i) => id === idsRef.current[i])
) {
idsRef.current = ids
}
const stableIds = idsRef.current
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? Is it just to protect against ordering issues in the ids param? Some accounts have lots of assets (e.g. NFT collections) so it might not be cheap to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison runs because callers like useAccountBalancesQuery create a new array every render via results.flatMap(...), even when the IDs haven't changed. Without this, useMemo([ids, network]) recomputes every render, recreating all query definitions and causing a re-render mess, which caused the app to feel very clunky and making even screen transitions feels dozens of seconds slower during my local tests.

But you are also right about the .every(), this can be simplified further. I'm pushing this change besides some explanation on why it's necessary.

Comment on lines 38 to 45
const idsRef = useRef(ids)
if (
ids.length !== idsRef.current.length ||
!ids.every((id, i) => id === idsRef.current[i])
) {
idsRef.current = ids
}
const stableIds = idsRef.current
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

@fmsouza fmsouza merged commit 1d77aa2 into main Feb 25, 2026
7 checks passed
@fmsouza fmsouza deleted the fmsouza/pera-3678 branch February 25, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants