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

fix(iOS) [0.74]: RCTRedBox not appearing in Bridgeless when metro is not running #43147

Closed

Conversation

okwasniewski
Copy link
Contributor

Summary:

When testing out 0.74.0-rc0 I found that when the metro is not running we are not displaying RedBox which bumps users to start the packager and reload the app. It also fixes the case where users try to reload by clicking the "Reload" button on RedBox.

Before

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-02-22.at.13.50.06.mp4

After

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-02-22.at.13.45.42.mp4

Changelog:

[IOS] [FIXED] - RCTRedBox not appearing in Bridgeless when metro is not running

Test Plan:

Build the app without metro running check if RedBox is shown

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner labels Feb 22, 2024
@okwasniewski okwasniewski force-pushed the fix/redbox-not-appearing branch from d32f1a9 to 3026f13 Compare February 22, 2024 12:51
@analysis-bot
Copy link

analysis-bot commented Feb 22, 2024

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 18,008,365 -4,139
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 21,366,887 -4,152
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: f7bbaff
Branch: main

@lunaleaps lunaleaps requested a review from philIip February 22, 2024 18:47
Copy link
Contributor

@dmytrorykun dmytrorykun left a comment

Choose a reason for hiding this comment

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

It looks like error handling is not implemented in RCTInstance. To solve this properly please implement a separate method called handleError that would be basically this:
https://github.com/facebook/react-native/blob/main/packages/react-native/React/CxxBridge/RCTCxxBridge.mm#L1068
Note that the _loading ivar does not exist in RCTInstance. You should assume it true.

@okwasniewski
Copy link
Contributor Author

@dmytrorykun I've extracted the code to a separate handleError method but I'm not sure if we should copy everything that's in RCTCxxBridge.mm handle error (there were hacks required to make old arch work). I've simplified the method, and everything seems to work as it should.

I have one issue with the JS raw stack as it's not attached when error is thrown:

should we ignore it or there is a way to retrieve it?

@okwasniewski okwasniewski force-pushed the fix/redbox-not-appearing branch from 3026f13 to 84c72b8 Compare February 29, 2024 11:16
Copy link
Contributor

@RSNara RSNara left a comment

Choose a reason for hiding this comment

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

I left a few questions!

@@ -339,6 +341,10 @@ - (void)_start
if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
installLegacyUIManagerConstantsProviderBinding(runtime);
}

RCTExecuteOnMainQueue(^{
RCTRegisterReloadCommandListener(self);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this reload change is necessary!

But, if it is, I have a request: Can we create a custom implementation of RCTReloadListener that retains RCTInstance weakly?

Bridgeless mode adheres to this principle:

Nothing outside of the RCTHost should own a reference to RCTInstance.

In practice, this line is fine: RCTRegisterReloadCommandListener holds on to RCTReloadListeners weakly.

But, I think bridgeless mode should not depend on this guarantee:

  1. Weak retention of listeners is an implementation detail of RCTRegisterReloadCommandListener. If someone changes it in the future, this bridgeless principle could be violated.
  2. Bridgeless classes should be responsible for enforcing bridgeless principles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was needed to make Reload button work in Redbox. I understand your concerns, I've tweaked the code to listen to notification through the notification center so now we don't need to worry about retaining this instance. WDYT about this approach?

Copy link
Contributor

@RSNara RSNara Mar 6, 2024

Choose a reason for hiding this comment

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

@okwasniewski, the current solution definitely addresses the instance retention issue.

But, I don't think it's a good idea to rely on a global event emission to communicate between RCTRedBox and RCTInstance. Many apps/environments actually run multiple react instances at the same time. Global event emission makes that configuration on iOS more difficult. (We don't have a need for this right now, but it's always nice to extend react native in ways that don't preclude, or make this more difficult). And also, more generally: if we can avoid reliance on global things, we probably should.

Was there any problem with creating a custom RCTReloadListener? Perhaps you noticed an issue, or have a concern, that hadn't crossed my mind.

Comment on lines +519 to +526
- (void)didReceiveReloadCommand {
[self _loadJSBundle:[self->_bridgeModuleDecorator.bundleManager bundleURL]];
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@okwasniewski, why did you end up registering the RCTInstance as a reload command listener here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When clicking Reload on the redbox nothing was happening

@okwasniewski okwasniewski force-pushed the fix/redbox-not-appearing branch from 03cf0dc to b41ab3b Compare March 5, 2024 14:26
@okwasniewski okwasniewski requested a review from RSNara March 6, 2024 13:45
@dmytrorykun
Copy link
Contributor

dmytrorykun commented Mar 6, 2024

Hey @okwasniewski , we are generally happy with the changes in this PR. But we would like to polish some details. Could you please resubmit this PR for the main branch. This way we'll be able to import it to our internal repo, and iterate on it faster. The goal is to land these changes before the 0.75-RC3.

@okwasniewski okwasniewski force-pushed the fix/redbox-not-appearing branch from 11f9f0d to 1be613b Compare March 7, 2024 11:01
@okwasniewski okwasniewski changed the base branch from 0.74-stable to main March 7, 2024 11:01
@okwasniewski okwasniewski force-pushed the fix/redbox-not-appearing branch from 1be613b to 08eefac Compare March 7, 2024 11:20
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Mar 7, 2024
@facebook-github-bot
Copy link
Contributor

@dmytrorykun has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@okwasniewski
Copy link
Contributor Author

okwasniewski commented Mar 8, 2024

Hey @dmytrorykun, @RSNara I'm going to be on PTO next week so I'm afraid I won't manage to implement custom implementation of RCTReloadListener are you guys okay with iterating on it internally?

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 8, 2024
@facebook-github-bot
Copy link
Contributor

@dmytrorykun merged this pull request in 4adef35.

huntie pushed a commit that referenced this pull request Mar 11, 2024
…not running (#43147)

Summary:
When testing out `0.74.0-rc0` I found that when the metro is not running we are not displaying RedBox which bumps users to start the packager and reload the app. It also fixes the case where users try to reload by clicking the "Reload" button on RedBox.

## Before

https://github.com/facebook/react-native/assets/52801365/086c557f-ea1f-4a97-b4c7-df8a945cc7a0

## After

https://github.com/facebook/react-native/assets/52801365/9f8421b3-5e83-466f-8cdb-38f97981275d

## Changelog:

[IOS] [FIXED] - RCTRedBox not appearing in Bridgeless when metro is not running

Pull Request resolved: #43147

Test Plan: Build the app without metro running check if RedBox is shown

Reviewed By: javache

Differential Revision: D54632056

Pulled By: dmytrorykun

fbshipit-source-id: fb6742898d3bd82545bfffd9175208e1a5984cb6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Callstack Partner: Callstack Partner Pick Request Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants