Skip to content
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

RJS-2673: Prevent flickering behavior in RealmProvider #6550

Merged
merged 5 commits into from
Apr 5, 2024
Merged

Conversation

elle-j
Copy link
Contributor

@elle-j elle-j commented Mar 14, 2024

What, How & Why?

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:

  1. 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.
  2. ..causing RealmProvider to rerender whenever the user is a new reference.
  3. ..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.
  4. ...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

@cla-bot cla-bot bot added the cla: yes label Mar 14, 2024
@elle-j elle-j requested a review from kraenhansen April 2, 2024 09:51
@elle-j elle-j marked this pull request as ready for review April 2, 2024 09:51
@elle-j elle-j merged commit 91de944 into main Apr 5, 2024
32 checks passed
@elle-j elle-j deleted the lj/rendering branch April 5, 2024 11:11
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react native: flashing of screens while realm loads. Cant navigate back
3 participants