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

[android][database] Remove all db references and listeners onCatalystInstanceDestroy #1535

Closed
wants to merge 2 commits into from

Conversation

Salakar
Copy link
Member

@Salakar Salakar commented Sep 27, 2018

Potential fix for #1498

cc @pistou , @barbarosh , @shashankvaibhav

@Salakar Salakar self-assigned this Sep 27, 2018
@Salakar Salakar added plugin: database Firebase Realtime Database platform: android labels Sep 27, 2018
@codecov
Copy link

codecov bot commented Sep 27, 2018

Codecov Report

Merging #1535 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1535   +/-   ##
=======================================
  Coverage   70.15%   70.15%           
=======================================
  Files          71       71           
  Lines        1833     1833           
=======================================
  Hits         1286     1286           
  Misses        547      547

@barbarosh
Copy link

@Salakar Looks like a good solution, but I think we should have this same solution and for iOS ?

@Salakar
Copy link
Member Author

Salakar commented Sep 27, 2018

@barbarosh I'd like someone to test and confirm this works before I look into iOS - I'm not even sure if iOS has the same issue - can someone confirm?

@Salakar Salakar added Workflow: Waiting for User Response Blocked waiting for user response. Workflow: Needs Review Pending feedback or review from a maintainer. labels Sep 27, 2018
@barbarosh
Copy link

@Salakar onHostDestroy isn't calling on a restart js part in dev mode.

@Salakar
Copy link
Member Author

Salakar commented Sep 27, 2018

@barbarosh have just checked and looks like that's an RN problem I think: facebook/react-native#9773

If someone could push up a cloneable repo that reproduces this it'd save me time and I can look into somehow working around it.

This change on this PR is most likely still be required either way.

@shashankvaibhav
Copy link

@Salakar You can use this method. It gets triggered when after hot reloading. I tried to use the code you wrote in onHostDestroy under this method but still no benefit.

@OverRide
public void onCatalystInstanceDestroy() {

}

@Salakar
Copy link
Member Author

Salakar commented Sep 27, 2018

Am trying something else - will push to this branch for you guys to test, give me a few mins.

@barbarosh
Copy link

@Salakar I tried this code


  @Override
  public void onCatalystInstanceDestroy() {
    super.onCatalystInstanceDestroy();
    Iterator refIterator = references.entrySet().iterator();
    while (refIterator.hasNext()) {
      Map.Entry pair = (Map.Entry) refIterator.next();
      RNFirebaseDatabaseReference nativeRef = (RNFirebaseDatabaseReference) pair.getValue();
      nativeRef.removeAllEventListeners();
      refIterator.remove(); // avoids a ConcurrentModificationException
    }
}

It worked, bot I worried, it code can clearify new subscriptions while starting new JS instance ?

@shashankvaibhav
Copy link

Guys in this method removeAllEventListeners() thers is a if statement with condition hasListeners.
It gives me false value after hot reload. This is the reason it is not going inside and removing listeners.

@Salakar
Copy link
Member Author

Salakar commented Sep 27, 2018

Can you locally replace the two files I've just changed again and let me know how you get on?

@shashankvaibhav
Copy link

@Salakar Sorry but didn't work. Same problem no data after hot reload.

@Salakar
Copy link
Member Author

Salakar commented Sep 27, 2018

@shashankvaibhav can you comment out the highlighted lines below (the iterator section) and try:

image

@shashankvaibhav
Copy link

@Salakar Didn't work.

@Salakar
Copy link
Member Author

Salakar commented Sep 28, 2018

Worked for @barbarosh though 🙈

Can you push up a reproducible project that I can clone and work off please to save me some time - and I can take a look

@armanatz
Copy link

@Salakar I tried this PR out and even commented out the lines you mentioned above. Still the same issue

@Salakar
Copy link
Member Author

Salakar commented Sep 28, 2018

@armanatz ok thanks for confirming also - I'll try reproduce on my end - will take time to setup though, I've also not experienced this issue myself so am not 100% sure if this is even the cause.

@barbarosh
Copy link

@Salakar for me worked solution with onCatalystInstanceDestroy callback, but i tried only for reload event from dev menu, I not check with hot reload

@armanatz
Copy link

@barbarosh Interesting because this PR doesn't work for me with dev menu reload

@Salakar
Copy link
Member Author

Salakar commented Sep 28, 2018

@barbarosh @armanatz what RN versions are you each using?

@armanatz
Copy link

@Salakar I am on [email protected] and [email protected].

@barbarosh
Copy link

@Salakar I am on [email protected] and [email protected].

@Salakar Salakar changed the title [android][database] Remove all db references and listeners onHostDestroy [android][database] Remove all db references and listeners onCatalystInstanceDestroy Oct 3, 2018
@Salakar
Copy link
Member Author

Salakar commented Oct 19, 2018

See new PR #1619

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: android plugin: database Firebase Realtime Database Workflow: Waiting for User Response Blocked waiting for user response.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants