Skip to content

Commit 57bed9a

Browse files
javachemeta-codesync[bot]
authored andcommitted
Cleanup bundle loading logic (#54403)
Summary: Pull Request resolved: #54403 Small tweaks to correct atomicity, set the thread name, and avoid a cop of the loaded bundle. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D85144130 fbshipit-source-id: a7ecdf5d33b5f30a62e00c4e5ac9fcfa93a056a2
1 parent 5465a51 commit 57bed9a

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <ReactCommon/TurboModuleBinding.h>
1111
#include <cxxreact/JSBigString.h>
12+
#include <folly/system/ThreadName.h>
1213
#include <glog/logging.h>
1314
#include <jserrorhandler/JsErrorHandler.h>
1415
#include <jsinspector-modern/InspectorFlags.h>
@@ -401,11 +402,13 @@ void ReactHost::destroyReactInstance() {
401402
}
402403

403404
void ReactHost::reloadReactInstance() {
404-
if (isReloadingReactInstance_) {
405+
if (isReloadingReactInstance_.exchange(true)) {
405406
return;
406407
}
407-
isReloadingReactInstance_ = true;
408+
408409
std::thread([this]() {
410+
folly::setThreadName("ReactReload");
411+
409412
std::vector<SurfaceManager::SurfaceProps> surfaceProps;
410413
for (auto& surfaceId : surfaceManager_->getRunningSurfaces()) {
411414
if (auto surfaceProp = surfaceManager_->getSurfaceProps(surfaceId);
@@ -469,9 +472,8 @@ bool ReactHost::loadScriptFromDevServer() {
469472
}
470473
})
471474
.get();
472-
auto script = std::make_unique<JSBigStdString>(response);
473-
reactInstance_->loadScript(
474-
std::move(script), devServerHelper_->getBundleUrl());
475+
auto script = std::make_unique<JSBigStdString>(std::move(response));
476+
reactInstance_->loadScript(std::move(script), bundleUrl);
475477
devServerHelper_->setupHMRClient();
476478
return true;
477479
} catch (...) {
@@ -486,6 +488,7 @@ bool ReactHost::loadScriptFromDevServer() {
486488
bool ReactHost::loadScriptFromBundlePath(const std::string& bundlePath) {
487489
try {
488490
LOG(INFO) << "Loading JS bundle from bundle path: " << bundlePath;
491+
// TODO: use platform-native asset loading strategy
489492
auto script = std::make_unique<JSBigStdString>(
490493
ResourceLoader::getFileContents(bundlePath));
491494
reactInstance_->loadScript(std::move(script), bundlePath);

packages/react-native/ReactCxxPlatform/react/threading/TaskDispatchThread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
namespace facebook::react {
2323

2424
TaskDispatchThread::TaskDispatchThread(
25-
std::string threadName,
25+
std::string_view threadName,
2626
int priorityOffset) noexcept
27-
: threadName_(std::move(threadName)) {
27+
: threadName_(threadName) {
2828
#ifdef ANDROID
2929
// Attaches the thread to JVM just in case anything calls out to Java
3030
thread_ = std::thread([&]() {

packages/react-native/ReactCxxPlatform/react/threading/TaskDispatchThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TaskDispatchThread {
2626
using TaskFn = std::function<void()>;
2727
using TimePoint = std::chrono::time_point<std::chrono::system_clock>;
2828

29-
TaskDispatchThread(std::string threadName = "", int priorityOffset = 0) noexcept;
29+
TaskDispatchThread(std::string_view threadName = "", int priorityOffset = 0) noexcept;
3030

3131
~TaskDispatchThread() noexcept;
3232

0 commit comments

Comments
 (0)