RJS-2673: Prevent flickering behavior in RealmProvider
#6550
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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