Skip to content

Commit db798c1

Browse files
zhongwuzwblakef
authored andcommitted
Fabric: Post RCTInstanceDidLoadBundle notification after bundle loaded (#48082)
Summary: Fixes #47949 ## Changelog: [IOS] [FIXED] - Fabric: Post RCTInstanceDidLoadBundle notification after bundle loaded Pull Request resolved: #48082 Test Plan: Post RCTInstanceDidLoadBundle notification after bundle loaded Reviewed By: philIip Differential Revision: D66754060 Pulled By: cipolleschi fbshipit-source-id: d30f0ed73e127936082e6f91e137b9b4013c6651
1 parent d4d1788 commit db798c1

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -236,47 +236,51 @@ std::string simpleBasename(const std::string& path) {
236236
*/
237237
void ReactInstance::loadScript(
238238
std::unique_ptr<const JSBigString> script,
239-
const std::string& sourceURL) {
239+
const std::string& sourceURL,
240+
std::function<void(jsi::Runtime& runtime)>&& completion) {
240241
auto buffer = std::make_shared<BigStringBuffer>(std::move(script));
241242
std::string scriptName = simpleBasename(sourceURL);
242243

243-
runtimeScheduler_->scheduleWork(
244-
[this,
245-
scriptName,
246-
sourceURL,
247-
buffer = std::move(buffer),
248-
weakBufferedRuntimeExecuter = std::weak_ptr<BufferedRuntimeExecutor>(
249-
bufferedRuntimeExecutor_)](jsi::Runtime& runtime) {
250-
SystraceSection s("ReactInstance::loadScript");
251-
bool hasLogger(ReactMarker::logTaggedMarkerBridgelessImpl);
252-
if (hasLogger) {
253-
ReactMarker::logTaggedMarkerBridgeless(
254-
ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str());
255-
}
244+
runtimeScheduler_->scheduleWork([this,
245+
scriptName,
246+
sourceURL,
247+
buffer = std::move(buffer),
248+
weakBufferedRuntimeExecuter =
249+
std::weak_ptr<BufferedRuntimeExecutor>(
250+
bufferedRuntimeExecutor_),
251+
completion](jsi::Runtime& runtime) {
252+
SystraceSection s("ReactInstance::loadScript");
253+
bool hasLogger(ReactMarker::logTaggedMarkerBridgelessImpl);
254+
if (hasLogger) {
255+
ReactMarker::logTaggedMarkerBridgeless(
256+
ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str());
257+
}
256258

257-
runtime.evaluateJavaScript(buffer, sourceURL);
259+
runtime.evaluateJavaScript(buffer, sourceURL);
258260

259-
/**
260-
* TODO(T183610671): We need a safe/reliable way to enable the js
261-
* pipeline from javascript. Remove this after we figure that out, or
262-
* after we just remove the js pipeline.
263-
*/
264-
if (!jsErrorHandler_->hasHandledFatalError()) {
265-
jsErrorHandler_->setRuntimeReady();
266-
}
261+
/**
262+
* TODO(T183610671): We need a safe/reliable way to enable the js
263+
* pipeline from javascript. Remove this after we figure that out, or
264+
* after we just remove the js pipeline.
265+
*/
266+
if (!jsErrorHandler_->hasHandledFatalError()) {
267+
jsErrorHandler_->setRuntimeReady();
268+
}
267269

268-
if (hasLogger) {
269-
ReactMarker::logTaggedMarkerBridgeless(
270-
ReactMarker::RUN_JS_BUNDLE_STOP, scriptName.c_str());
271-
ReactMarker::logMarkerBridgeless(
272-
ReactMarker::INIT_REACT_RUNTIME_STOP);
273-
ReactMarker::logMarkerBridgeless(ReactMarker::APP_STARTUP_STOP);
274-
}
275-
if (auto strongBufferedRuntimeExecuter =
276-
weakBufferedRuntimeExecuter.lock()) {
277-
strongBufferedRuntimeExecuter->flush();
278-
}
279-
});
270+
if (hasLogger) {
271+
ReactMarker::logTaggedMarkerBridgeless(
272+
ReactMarker::RUN_JS_BUNDLE_STOP, scriptName.c_str());
273+
ReactMarker::logMarkerBridgeless(ReactMarker::INIT_REACT_RUNTIME_STOP);
274+
ReactMarker::logMarkerBridgeless(ReactMarker::APP_STARTUP_STOP);
275+
}
276+
if (auto strongBufferedRuntimeExecuter =
277+
weakBufferedRuntimeExecuter.lock()) {
278+
strongBufferedRuntimeExecuter->flush();
279+
}
280+
if (completion) {
281+
completion(runtime);
282+
}
283+
});
280284
}
281285

282286
/*

packages/react-native/ReactCommon/react/runtime/ReactInstance.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class ReactInstance final : private jsinspector_modern::InstanceTargetDelegate {
4949

5050
void loadScript(
5151
std::unique_ptr<const JSBigString> script,
52-
const std::string& sourceURL);
52+
const std::string& sourceURL,
53+
std::function<void(jsi::Runtime& runtime)>&& completion = nullptr);
5354

5455
void registerSegment(uint32_t segmentId, const std::string& segmentPath);
5556

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,9 @@ - (void)_loadScriptFromSource:(RCTSource *)source
472472

473473
auto script = std::make_unique<NSDataBigString>(source.data);
474474
const auto *url = deriveSourceURL(source.url).UTF8String;
475-
_reactInstance->loadScript(std::move(script), url);
476-
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTInstanceDidLoadBundle" object:nil];
475+
_reactInstance->loadScript(std::move(script), url, [](jsi::Runtime &_) {
476+
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTInstanceDidLoadBundle" object:nil];
477+
});
477478
}
478479

479480
- (void)_handleJSError:(const JsErrorHandler::ParsedError &)error withRuntime:(jsi::Runtime &)runtime

0 commit comments

Comments
 (0)