Skip to content

Fix Connect to Metro after Reload in Bridgeless mode - #43994

Closed
cipolleschi wants to merge 1 commit into
react:mainfrom
cipolleschi:export-D55916135
Closed

Fix Connect to Metro after Reload in Bridgeless mode#43994
cipolleschi wants to merge 1 commit into
react:mainfrom
cipolleschi:export-D55916135

Conversation

@cipolleschi

Copy link
Copy Markdown
Contributor

Summary:
We received this issue from OSS where an app can't connect to Metro on reloads in the following scenario:

  • Start the App when metro does not run.
  • Observe the error screen
  • Start Metro
  • Press Reload
  • Observe the error message again

While the desired behavior should be to connect to Metro now that this is running.

The root cause of the problem is that the RCTHost is initialized with a value of the bundleURL that is nil. Upon reload, the RCTHost is not recreated: the instance is restarted, but with the previous bundleURL, which is still nil.

The solution is to initialize the RCTHost with a closure that re-evaluate the bundleURL whenever it is invoked and to evaluate it only on start, to keep the initialization path light.
This way, when the app is started with Metro not running, the bundleURL is nil. But when it is reloaded with Metro starting, the bundleURL is properly initialized.

Note that the changes in this diff are not breaking as I reimplemented (and deprecated) the old initializer so that they should work in the same way.

Changelog:

[iOS][Fixed] - Let RCTHost be initialized with a function to provide the bundleURL so that it can connect to metro on Reload when the url changes.

Differential Revision: D55916135

@facebook-github-botfacebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 9, 2024
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D55916135

@cipolleschi

Copy link
Copy Markdown
ContributorAuthor

cc. @okwasniewski

@analysis-bot

analysis-bot commented Apr 9, 2024

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a19,217,881+0
androidhermesarmeabi-v7an/a--
androidhermesx86n/a--
androidhermesx86_64n/a--
androidjscarm64-v8a22,594,629+2
androidjscarmeabi-v7an/a--
androidjscx86n/a--
androidjscx86_64n/a--

Base commit: b23960a
Branch: main

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D55916135

Summary:
We received [this issue](#43764) from OSS where an app can't connect to Metro on reloads in the following scenario:
* Start the App when metro does not run.
* Observe the error screen
* Start Metro
* Press Reload
* Observe the error message again
While the desired behavior should be to connect to Metro now that this is running.
The root cause of the problem is that the RCTHost is initialized with a value of the `bundleURL` that is `nil`. Upon reload, the RCTHost is **not** recreated: the instance is restarted, but with the previous `bundleURL`, which is still `nil`.
The solution is to initialize the `RCTHost` with a closure that re-evaluate the `bundleURL` whenever it is invoked and to evaluate it only on `start`, to keep the initialization path light.
This way, when the app is started with Metro not running, the `bundleURL` is `nil`. But when it is reloaded with Metro starting, the `bundleURL` is properly initialized.
Note that the changes in this diff are not breaking as I reimplemented (and deprecated) the old initializer so that they should work in the same way.
## Changelog:
[iOS][Fixed] - Let RCTHost be initialized with a function to provide the `bundleURL` so that it can connect to metro on Reload when the url changes.
Reviewed By: dmytrorykun
Differential Revision: D55916135
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D55916135

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 8b8b85b.

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Apr 9, 2024
@github-actions

Copy link
Copy Markdown

This pull request was successfully merged by @cipolleschi in 8b8b85b.

When will my fix make it into a release? | How to file a pick request?

cipolleschi added a commit that referenced this pull request Apr 9, 2024
Summary:
Pull Request resolved: #43994
We received [this issue](#43764) from OSS where an app can't connect to Metro on reloads in the following scenario:
* Start the App when metro does not run.
* Observe the error screen
* Start Metro
* Press Reload
* Observe the error message again
While the desired behavior should be to connect to Metro now that this is running.
The root cause of the problem is that the RCTHost is initialized with a value of the `bundleURL` that is `nil`. Upon reload, the RCTHost is **not** recreated: the instance is restarted, but with the previous `bundleURL`, which is still `nil`.
The solution is to initialize the `RCTHost` with a closure that re-evaluate the `bundleURL` whenever it is invoked and to evaluate it only on `start`, to keep the initialization path light.
This way, when the app is started with Metro not running, the `bundleURL` is `nil`. But when it is reloaded with Metro starting, the `bundleURL` is properly initialized.
Note that the changes in this diff are not breaking as I reimplemented (and deprecated) the old initializer so that they should work in the same way.
[iOS][Fixed] - Let RCTHost be initialized with a function to provide the `bundleURL` so that it can connect to metro on Reload when the url changes.
Reviewed By: dmytrorykun
Differential Revision: D55916135
fbshipit-source-id: 6927b2154870245f28f42d26bd0209b28c9518f2
cortinico pushed a commit that referenced this pull request Apr 10, 2024
* Support launchOptions in bridgeless mode (#43757)
Summary:
Support launchOptions in bridgeless mode
bypass-github-export-checks
[IOS] [FIXED] - Support launchOptions in bridgeless mode
Pull Request resolved: #43757
Test Plan:
```
useEffect(() => {
const processInitialURL = async () => {
const url = await Linking.getInitialURL();
if (url !== null) {
console.log(`Initial url is: ${url}`);
}
};
processInitialURL();
}, []);
```
Reviewed By: javache
Differential Revision: D55790758
Pulled By: cipolleschi
fbshipit-source-id: 0f6aa6bdcebfc5bc42d632bea9193f122c1eb84f
* Fix Connect to Metro after Reload in Bridgeless mode (#43994)
Summary:
Pull Request resolved: #43994
We received [this issue](#43764) from OSS where an app can't connect to Metro on reloads in the following scenario:
* Start the App when metro does not run.
* Observe the error screen
* Start Metro
* Press Reload
* Observe the error message again
While the desired behavior should be to connect to Metro now that this is running.
The root cause of the problem is that the RCTHost is initialized with a value of the `bundleURL` that is `nil`. Upon reload, the RCTHost is **not** recreated: the instance is restarted, but with the previous `bundleURL`, which is still `nil`.
The solution is to initialize the `RCTHost` with a closure that re-evaluate the `bundleURL` whenever it is invoked and to evaluate it only on `start`, to keep the initialization path light.
This way, when the app is started with Metro not running, the `bundleURL` is `nil`. But when it is reloaded with Metro starting, the `bundleURL` is properly initialized.
Note that the changes in this diff are not breaking as I reimplemented (and deprecated) the old initializer so that they should work in the same way.
[iOS][Fixed] - Let RCTHost be initialized with a function to provide the `bundleURL` so that it can connect to metro on Reload when the url changes.
Reviewed By: dmytrorykun
Differential Revision: D55916135
fbshipit-source-id: 6927b2154870245f28f42d26bd0209b28c9518f2
* Fix badly resolved merge conflicts
---------
Co-authored-by: zhongwuzw <zhongwuzw@qq.com>
This was referenced Jun 28, 2024
@cipolleschicipolleschi mentioned this pull request Jul 22, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.fb-exportedMergedThis PR has been merged.p: FacebookPartner: FacebookPartner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@cipolleschi@facebook-github-bot@analysis-bot