Skip to content

Commit 782e06a

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
LogBox: do less work in production when LogBox shouldn't even be running
Summary: Do we need this? Is it possible for any of these codepaths to execute in production? If so, it would be nice to avoid NPEs or even scheduling work on the UI thread. Maybe we want to add soft exception logging for if these paths are called? Changelog: [Internal] make sure LogBox does even less work when it's not hooked up Reviewed By: rickhanlonii Differential Revision: D20156812 fbshipit-source-id: ba9faedcb3b0951e6913724ca99549dc2d16237e
1 parent e1de7a5 commit 782e06a

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

ReactAndroid/src/main/java/com/facebook/react/devsupport/LogBoxModule.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ public LogBoxModule(ReactApplicationContext reactContext, DevSupportManager devS
3232
super(reactContext);
3333

3434
mDevSupportManager = devSupportManager;
35+
3536
UiThreadUtil.runOnUiThread(
3637
new Runnable() {
3738
@Override
3839
public void run() {
39-
if (mReactRootView == null) {
40+
if (mReactRootView == null && mDevSupportManager != null) {
4041
mReactRootView = mDevSupportManager.createRootView("LogBox");
4142
if (mReactRootView == null) {
4243
FLog.e(
@@ -55,25 +56,27 @@ public String getName() {
5556

5657
@Override
5758
public void show() {
58-
UiThreadUtil.runOnUiThread(
59-
new Runnable() {
60-
@Override
61-
public void run() {
62-
if (mLogBoxDialog == null && mReactRootView != null) {
63-
Activity context = getCurrentActivity();
64-
if (context == null || context.isFinishing()) {
65-
FLog.e(
66-
ReactConstants.TAG,
67-
"Unable to launch logbox because react activity "
68-
+ "is not available, here is the error that logbox would've displayed: ");
69-
return;
59+
if (mReactRootView != null) {
60+
UiThreadUtil.runOnUiThread(
61+
new Runnable() {
62+
@Override
63+
public void run() {
64+
if (mLogBoxDialog == null && mReactRootView != null) {
65+
Activity context = getCurrentActivity();
66+
if (context == null || context.isFinishing()) {
67+
FLog.e(
68+
ReactConstants.TAG,
69+
"Unable to launch logbox because react activity "
70+
+ "is not available, here is the error that logbox would've displayed: ");
71+
return;
72+
}
73+
mLogBoxDialog = new LogBoxDialog(context, mReactRootView);
74+
mLogBoxDialog.setCancelable(false);
75+
mLogBoxDialog.show();
7076
}
71-
mLogBoxDialog = new LogBoxDialog(context, mReactRootView);
72-
mLogBoxDialog.setCancelable(false);
73-
mLogBoxDialog.show();
7477
}
75-
}
76-
});
78+
});
79+
}
7780
}
7881

7982
@Override
@@ -83,7 +86,7 @@ public void hide() {
8386
@Override
8487
public void run() {
8588
if (mLogBoxDialog != null) {
86-
if (mReactRootView.getParent() != null) {
89+
if (mReactRootView != null && mReactRootView.getParent() != null) {
8790
((ViewGroup) mReactRootView.getParent()).removeView(mReactRootView);
8891
}
8992
mLogBoxDialog.dismiss();

0 commit comments

Comments
 (0)