-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[No QA] fix: null check for app state subscription added #6936
Conversation
@TomatoToaster Before you merge, I would recommend checking the discussion on upgrading the RN in the linked issue. |
Also, if we want to merge this PR, it needs the |
|
@@ -26,6 +26,9 @@ function addBecameActiveListener(callback) { | |||
} | |||
const appStateChangeSubscription = AppState.addEventListener('change', appStateChangeCallback); | |||
return () => { | |||
if (!appStateChangeSubscription) { | |||
return; | |||
} | |||
appStateChangeSubscription.remove(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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:
- Constructor initializes
appStateChangeSubscription
tonull
. - Component mounts,
componentDidMount
runs and starts creating the subscription. - Component unmounts and
componentWillUnmount
runs beforecomponentDidMount
finishes creating the subscription. So the subscription is still null 💥
There was a problem hiding this comment.
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 :)
[No QA] fix: null check for app state subscription added (cherry picked from commit b930390)
🚀 Deployed to staging by @TomatoToaster in version: 1.1.24-19 🚀
|
🚀 Deployed to production by @francoisl in version: 1.1.24-19 🚀
|
Details
Fixed Issues
$ #6932
Tests
QA Steps
Tested On
Screenshots
Web
Mobile Web
Desktop
iOS
Android