This PR makes the internal fields of User non-enumerable in order to hide them during deep comparisons. It also updates the UserProvider to only setUser() when specific fields change.
A plausible reason for the flickering behavior described in #6333 is:
The user in UserProvider would continuously have its listener added (and removed) (in v0.6.2), setting the user to a new reference in its listener callback each time.
..causing RealmProvider to rerender whenever the user is a new reference.
..causing RealmProvider to check if the configuration has changed (!areConfigurationsIdentical()) and force a rerender if it has. In cases where it should not have changed, the function indicated that it had. The function uses Lodash's isEqual() which does a deep comparison that included the User's internal fields as they were still enumerable. For objects with properties being set to functions (e.g. User.listeners.options), those will be different references if the user itself is a different reference.
...causing the useEffect callback where the Realm is opened and closed in RealmProvider to run (setting the realm to the opened realm, then to null when unmounted). The switch between realm and null renders either the children or the fallback respectively. The repeated behavior causes the flickering.
This closes #6333
☑️ ToDos
[ ] 📝 Changelog entry
[ ] 📝 Compatibility label is updated or copied from previous entry
[ ] 📝 Update COMPATIBILITY.md
[ ] 🚦 Tests
[ ] 📦 Updated internal package version in consuming package.jsons (if updating internal packages)
[ ] 📱 Check the React Native/other sample apps work if necessary
[ ] 💥 Breaking label has been applied or is not necessary
What, How & Why?
This PR makes the internal fields of
User
non-enumerable in order to hide them during deep comparisons. It also updates theUserProvider
to onlysetUser()
when specific fields change.A plausible reason for the flickering behavior described in #6333 is:
user
inUserProvider
would continuously have its listener added (and removed) (inv0.6.2
), setting theuser
to a new reference in its listener callback each time.RealmProvider
to rerender whenever theuser
is a new reference.RealmProvider
to check if the configuration has changed (!areConfigurationsIdentical()
) and force a rerender if it has. In cases where it should not have changed, the function indicated that it had. The function uses Lodash'sisEqual()
which does a deep comparison that included theUser
's internal fields as they were still enumerable. For objects with properties being set to functions (e.g.User.listeners.options
), those will be different references if the user itself is a different reference.useEffect
callback where the Realm is opened and closed inRealmProvider
to run (setting therealm
to the opened realm, then tonull
when unmounted). The switch betweenrealm
andnull
renders either thechildren
or thefallback
respectively. The repeated behavior causes the flickering.This closes #6333
☑️ ToDos
Compatibility
label is updated or copied from previous entryCOMPATIBILITY.md
package.json
s (if updating internal packages)Breaking
label has been applied or is not necessary