-
Notifications
You must be signed in to change notification settings - Fork 576
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
useObject will return referentially different objects for the same object #4521
Comments
Sounds like a good enhancement. I did attempt something similar to this at the beginning of the hooks effort, but opted for the simpler approach. I do believe it's a good idea to share the cached objects between hooks calls when requesting the same data. We will get this planned and update as progress is made. |
I have a pretty clear idea of how to implement this. I could throw together an implementation quite quickly. The slower part will be testing. Perhaps I could make a PR to an upstream feature branch which we could collaborate on to fully test? Would this be useful or would you prefer to tackle it all in house? |
If you made a PR, it would help get the feature out faster. But of course, we would need some tests surrounding it. We are using As this package is quite new, we haven't really written any guides on how to contribute. I'll write a guide here and then transfer that into a contribution document.
I assume you are already setup to run a
That should be enough to get started. If you are making changes to c++ code then I recommend setting up The rest of the steps are as follows.
That should be enough to get started. Just shout if you have any questions. |
This has been resolved in |
Issue is still present as #4544 has never been merged |
How frequently does the bug occur?
All the time
Description
Given the immutability conventions of react you would expect that
However this is not the case.
Referential equality is commonplace for the equivalent of useObject in all the most common state libraries such as redux, mobx and zustand. It's very common to use hooks instead of prop drilling and therefore natural to use
useObject
multiple times for the same object. This issue could produce potential gotchas for users such as unnecessary re-renders.One solution would be to maintain an object cache, each object would only have a single realm listener. The cache entry would track the number of active hooks there are for the object via list of plain JS listener callbacks. When the component unmounts the listener would be removed from the list of listeners. When the list of listeners drops to 0 the cache entry would be purged.
This model would likely have some other benefits
useObject
as a new realm object instance and listener wouldn't have to be made if it was already in the cacheA similar approach could be applied to
useQuery
Stacktrace & log output
No response
Can you reproduce the bug?
Yes, always
Reproduction Steps
No response
Version
main
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
ios
Build environment
Which debugger for React Native: ..
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: