Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/libs/AppStateMonitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function addBecameActiveListener(callback) {
}
const appStateChangeSubscription = AppState.addEventListener('change', appStateChangeCallback);
return () => {
if (!appStateChangeSubscription) {
return;
}
appStateChangeSubscription.remove();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code change still makes sense regardless right? It might be redundant with the RN upgrade if that makes it so appStateChangeSubscription is never null, but it wouldn't hurt to have this check.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dope then I think it's safe to merge!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think including the null check is a good idea even in RN 0.65+, because, while unlikely, I think we could potentially have a race condition like this if a component mounts and unmounts almost instantly:

  1. Constructor initializes appStateChangeSubscription to null.
  2. Component mounts, componentDidMount runs and starts creating the subscription.
  3. Component unmounts and componentWillUnmount runs before componentDidMount finishes creating the subscription. So the subscription is still null 💥

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Thanks for the explanation :)

};
}
Expand Down