-
Notifications
You must be signed in to change notification settings - Fork 561
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 always returns referentially different objects #4913
Comments
@mordechaim Thank you for reporting. You are right, and similar behaviour has been reported in #4513. We need to wrap up #4519 to get a fix in. |
@kneth thank you. As an aside: with this issue fixed, will filtered collections also remain referentially the same object given the same filters? So if I do:
Will the memo be retained? |
For now, you will have to do const cats = useQuery('Cat');
const brownCats = useMemo(cats.filtered('color == "brown"), [cats]); |
@mordechaim Thanks for reporting this. We have it planned and hopefully will get around to merging the fix to this soon. We just need to write regression tests to make sure this doesn't happen again. I am closing this issue there is already a related issue and a PR. |
Argh, same. Just stumbled upon this issue after creating #5264 . |
How frequently does the bug occur?
All the time
Description
According to the comments in the following code snippet:
realm-js/packages/realm-react/src/useQuery.tsx
Lines 58 to 62 in a7c8c9f
Which relies on cached collections:
realm-js/packages/realm-react/src/cachedCollection.ts
Lines 56 to 59 in a7c8c9f
The result of
useQuery
should remain referentially the same so we could use it as a dependency foruseMemo
and friends. I cleary observe otherwise, on each render the returned collection is different and breaks my memoization.Stacktrace & log output
No response
Can you reproduce the bug?
Yes, always
Reproduction Steps
Given a schema
Cat
The console will output
memo busted
on each press.Version
11.0.0-rc.0
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
Android 11
Build environment
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: