-
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
BUG - useQuery() does NOT return a stable reference, so a filter or sort in a useMemo is performed EVERY render #5264
Comments
This is a pretty foundational/serious issue for me to hit... has anyone else been using Realm React, or am I the first? |
@channeladam I have same issue and I regret starting with realm:
|
@channeladam I've expanded our tests and have confirmed that this is indeed occurring. I will start working on a fix for both |
@channeladam PR is up for review. This will stablize the references for the following cases:
|
@takameyer wonderful, thank you! Is there a estimated timeline for the next public release of the package? |
@channeladam Likely this week or early next week. |
@channeladam |
I'm still seeing this problem in 0.4.3, this is why I stumbled on this issue actually. The only difference with the previous example is that I modify a boolean props of an item of the collection with realm.write before comparing references. This is actually what triggers the re-render of the whole component. Is thi to be expected ? |
@badaz If you make a change to an item within a collection, then the collection reference will be updated. However, any other items in the collection will keep their original reference, so you should be able to create a rendering component for each item using |
@badaz In any case, if it's not working as you would expect, please open a new issue so we can track it and go from there. |
Ok thanks, I'll try this |
I'm still struggling with this issue. |
I figured out that. The issue just happens when I use |
How frequently does the bug occur?
Always
Description
Expected useQuery to return a stable reference so any filtered() or sorted() done in a useMemo() would not be performed on every re-render.
Stacktrace & log output
No response
Can you reproduce the bug?
Always
Reproduction Steps
Create the TypeScript example as per the doco:
npx react-native init AwesomeRealmProject --template @realm/react-native-template-ts
Tweak the TypeScript example's AppNonSync.tsx to demonstrate the issue.
The changes simply setup a timer to force a rerender every half second.
The callback in the useMemo is executed every render, even though
result
should not have changed.Version
Same as template - and latest 11.3.1
What services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
Android 11 R API 30 - Pixel 5 emulator
Build environment
Which debugger for React Native: ..
Flipper
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: