-
Notifications
You must be signed in to change notification settings - Fork 24.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
[iOS] Support launchOptions in bridgeless mode #43757
[iOS] Support launchOptions in bridgeless mode #43757
Conversation
RCTBridge *bridge = self.bridge; | ||
if (!bridge) { | ||
bridge = [RCTBridge currentBridge]; | ||
} |
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.
Modules are always scoped to a single bridge. Accessing the singleton here is incorrect.
If bridge
is nil, it means this module is being destroyed and the module should be torn down.
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.
emm,in the bridgeless mode, bridge ivar is always nil because it is a turbo module.
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.
Hmm, isn't this part of bridgeless compat? @cipolleschi ?
Accessing the singleton here is an anti-pattern and should be avoided.
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 agree with @javache that we should not access the [RCTBridge currentBridge]
.
In bridgeless mode, self.bridge
would be nil, and the currentBridge
will return the bridgeProxy
that behaves like a bridge. So, this technically works, but it was intended to be used only for backward compatibility.
However, I'd rather fix the issue properly, looking if we can find a way to remove the reference to the bridge altogether. There are only three reference to the bridge in the RCTLinkingManager
: if we find a place to store the launchOptions
which can work for both Old and New Architecture, that would be great.
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.
Also... this should actually works already: in bridgeless mode, this module should be created by the RCTTurboModuleManager
here.
This method checks whether there exists a _bridge
or a _bridgeProxy
and it sets the bridge
ivar with the _bridge
or the _bridgeProxy
object (here).
So, my guess is that the
if (!bridge) {
bridge = [RCTBridge currentBridge];
}
Is not necessary at all, but we need to store the launchOptions
in the bridgeProxy
.
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.
@cipolleschi you can see it also check _isLegacyModuleClass
of class
, so only legacy module can be set _bridgeProxy in bridgeless mode.
if (_bridge) {
[(id)module setValue:_bridge forKey:@"bridge"];
} else if (_bridgeProxy && [self _isLegacyModuleClass:[module class]]) {
[(id)module setValue:_bridgeProxy forKey:@"bridge"];
}
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.
True, but _isLegacyModuleClass
checks this. I think that this should be turned on in the OSS to simplify the migration...
I think we should just remove the && _isLegacyModuleClass
in that check. We are already checking that the module supports the bridge
property, so it would be better to just set the bridgeProxy if it's available.
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.
@cipolleschi Done, please review again.
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.
This is good enough to unblock us in the short term. We should still look for a way to remove the dependency RCTLinkingManager -> RCTBridge for when we are going to remove it.
/rebase - (this triggers an automatic rebase - build android should be green on main!) |
e002f9c
to
37bf818
Compare
37bf818
to
f065614
Compare
Base commit: c1081cc |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@cipolleschi merged this pull request in 90296be. |
This pull request was successfully merged by @zhongwuzw in 90296be. When will my fix make it into a release? | How to file a pick request? |
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
* 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>
Summary: We would set the value of _bridge ivar to bridgeProxy for turbo module in bridgeless mode in #43757 , so we need to change the way of bridgeless/bridge check. ## Changelog: [IOS] [FIXED] - Change bridgeless check in dev menu Pull Request resolved: #43976 Test Plan: Dev menu shows bridgeless/bridge mode correctly. Reviewed By: christophpurrer Differential Revision: D56056640 Pulled By: cipolleschi fbshipit-source-id: 1358c3027c1d5f12c70dd4486cc1d5975c7a185a
Summary: We would set the value of _bridge ivar to bridgeProxy for turbo module in bridgeless mode in #43757 , so we need to change the way of bridgeless/bridge check. ## Changelog: [IOS] [FIXED] - Change bridgeless check in dev menu Pull Request resolved: #43976 Test Plan: Dev menu shows bridgeless/bridge mode correctly. Reviewed By: christophpurrer Differential Revision: D56056640 Pulled By: cipolleschi fbshipit-source-id: 1358c3027c1d5f12c70dd4486cc1d5975c7a185a
Summary:
Support launchOptions in bridgeless mode
Changelog:
[IOS] [FIXED] - Support launchOptions in bridgeless mode
Test Plan: