-
Notifications
You must be signed in to change notification settings - Fork 464
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
useQuery not returning stable references #2701
Comments
We have gone over this quite a few times in issues/discussions, we do our best to provide stable references but at the end of the day it isn't the most important thing. i.e. a re-render isn't the expensive thing, memoizing everything and doing deep equality might be a lot more expensive if we'd do that on every query. The best bet for us is to ensure you have the most up-to-date data and you can optimize the re-render process yourself by means of Other issues #425 (comment) |
@JoviDeCroock the code is fully memoized. But if the object references keep changing, memoizing has no effect. It sounds like you're saying this is by design, not that big of a deal, and that if you're using urql, you should just expect rerenders? |
I don't really accept that this impossible or that it's it is unimportant. I just rebuilt the same demo with apollo client and it behaves exactly as you'd expect, the memoization works and rerenders are prevented: Apollo client repro: sarink/urql-perf#3 |
Just to send an update, this could be an issue with Graphcache losing the reference to the last result, but I haven't looked into this just yet |
This is destroying our rendering performance, and with memoizations having no effect, I don't think there's anything consumers can do about it? I'm surprised more people haven't noticed/this isn't of high importance Is this something that could be fixed in v3? Or a regression that could be fixed by downgrading? |
I mean, you can do a short-term fix if that is what you are looking for by leveraging useMemo(() => result.data.todos, [JSON.stringify(result.data.todos)] |
Some initial observations from going through this
so I guess we can boil this down to two distinct issues, one where we aren't removing |
@sarink we were just testing this and noticed you are using an old version of graphcache, when updating to the latest version we do see this working.... However we did notice that there's a bug with returning partial optimistic results, as in when you toggle the item it won't show up after the optimistic update unless we add |
Describe the bug
I hope that I'm simply misunderstanding or have misconfigured something, but I can't seem to figure out why objects inside
useQuery().data.MyQuery.someList[index]
are changing references. This means they cannot be memoized, and the application rerenders unnecessarilyThanks :)
For skimming (if you don't want to pull the repro repo):
Reproduction
sarink/urql-perf#2
Urql version
^2.2.3
Validations
The text was updated successfully, but these errors were encountered: