-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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] Fabric: Post RCTInstanceDidLoadBundle notification after bundle loaded #48082
base: main
Are you sure you want to change the base?
[iOS] Fabric: Post RCTInstanceDidLoadBundle notification after bundle loaded #48082
Conversation
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.
Thanks for looking into this, it was next o my todo list! xD
I left a couple of suggestion to improve the solution.
@@ -476,7 +476,11 @@ - (void)_loadScriptFromSource:(RCTSource *)source | |||
auto script = std::make_unique<NSDataBigString>(source.data); | |||
const auto *url = deriveSourceURL(source.url).UTF8String; | |||
_reactInstance->loadScript(std::move(script), url); | |||
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTInstanceDidLoadBundle" object:nil]; | |||
[self callFunctionOnBufferedRuntimeExecutor:[](facebook::jsi::Runtime &_) { |
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 jumps to a different thread and then we jumps back to the original one. I'm not super excited about this: what do you think about changing the ReactInstance::loadScript
method to take an extra, optional parameter (nullptr
as default value) which is a callback and invoke the callback when loadScript
finishes?
It should prevent us a thread jump and ensure that we are actually posting the notification when the script has been loaded.
We can check here if the callback is set and invoke it.
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.
@@ -476,7 +476,11 @@ - (void)_loadScriptFromSource:(RCTSource *)source | |||
auto script = std::make_unique<NSDataBigString>(source.data); | |||
const auto *url = deriveSourceURL(source.url).UTF8String; | |||
_reactInstance->loadScript(std::move(script), url); | |||
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTInstanceDidLoadBundle" object:nil]; | |||
[self callFunctionOnBufferedRuntimeExecutor:[](facebook::jsi::Runtime &_) { | |||
dispatch_async(dispatch_get_main_queue(), ^{ |
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.
why are we jumping back on the UI thread? I don't think that it is necessary: we should be able to post notification from a background thread.
What happens if we dispatch the notification from a different thread?
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 I just keep the same logic as old arch, please see
dispatch_async(dispatch_get_main_queue(), ^{ |
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.
Thanks for applying the feedback!
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary:
Fixes #47949
Changelog:
[IOS] [FIXED] - Fabric: Post RCTInstanceDidLoadBundle notification after bundle loaded
Test Plan:
Post RCTInstanceDidLoadBundle notification after bundle loaded