Skip to content

Commit

Permalink
Add null check for context in redbox surface delegate
Browse files Browse the repository at this point in the history
Summary:
The context could be null or is finishing when we create the redbox surface content view. This diff adds the null check and delegate the message in log when context is not available.

Changelog:
[Android][Fixed] - Adding null check for context in redbox surface delegate

Differential Revision: D34930595

fbshipit-source-id: 91508ded7821033abcd893f70bcfe3cc9ee5b5c2
  • Loading branch information
ryancat authored and facebook-github-bot committed Mar 16, 2022
1 parent 8200f91 commit 9527ab1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ private void showNewError(
new Runnable() {
@Override
public void run() {
// Keep a copy of the latest error to be shown by the RedBoxSurface
updateLastErrorInfo(message, stack, errorCookie, errorType);

if (mRedBoxSurfaceDelegate == null) {
@Nullable SurfaceDelegate redBoxSurfaceDelegate = createSurfaceDelegate("RedBox");
if (redBoxSurfaceDelegate != null) {
Expand All @@ -361,8 +364,6 @@ public void run() {
return;
}

// The RedBox surface delegate will always show the latest error
updateLastErrorInfo(message, stack, errorCookie, errorType);
mRedBoxSurfaceDelegate.show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public void createContentView(String appKey) {
// used here.
RedBoxHandler redBoxHandler = mDevSupportManager.getRedBoxHandler();
Activity context = mDevSupportManager.getCurrentActivity();
if (context == null || context.isFinishing()) {
@Nullable String message = mDevSupportManager.getLastErrorTitle();
FLog.e(
ReactConstants.TAG,
"Unable to launch redbox because react activity "
+ "is not available, here is the error that redbox would've displayed: "
+ (message != null ? message : "N/A"));
return;
}
// Create a new RedBox when currentActivity get updated
mRedBoxContentView = new RedBoxContentView(context);
mRedBoxContentView
Expand Down

0 comments on commit 9527ab1

Please sign in to comment.