Skip to content

Commit 784c862

Browse files
EdmondChuiHWfacebook-github-bot
authored andcommitted
Fusebox reload-to-profile (facebook#46856)
Summary: Changelog: [General][Added] - Add support for reload-to-profile in Fusebox. CDT: facebook/react-native-devtools-frontend#117 React: facebook/react#31021 This diff adds support for reload2profile under bridge and bridgeless for iOS, Android, and C++ Reviewed By: hoxyq Differential Revision: D63233256
1 parent 768a1d8 commit 784c862

File tree

16 files changed

+375
-0
lines changed

16 files changed

+375
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <Foundation/Foundation.h>
9+
10+
@interface RCTDevToolsRuntimeSettingsModule : NSObject
11+
12+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <FBReactNativeSpec/FBReactNativeSpec.h>
9+
#import <React/RCTDevToolsRuntimeSettingsModule.h>
10+
11+
#import "CoreModulesPlugins.h"
12+
13+
struct Config {
14+
bool shouldReloadAndProfile = false;
15+
bool recordChangeDescriptions = false;
16+
};
17+
18+
// static to persist across Turbo Module reloads
19+
static Config _config;
20+
21+
@interface RCTDevToolsRuntimeSettingsModule () <NativeReactDevToolsRuntimeSettingsModuleSpec> {
22+
}
23+
@end
24+
25+
@implementation RCTDevToolsRuntimeSettingsModule
26+
RCT_EXPORT_MODULE(ReactDevToolsRuntimeSettingsModule)
27+
28+
RCT_EXPORT_METHOD(setReloadAndProfileConfig
29+
: (JS::NativeReactDevToolsRuntimeSettingsModule::PartialReloadAndProfileConfig &)config)
30+
{
31+
if (config.shouldReloadAndProfile().has_value()) {
32+
_config.shouldReloadAndProfile = config.shouldReloadAndProfile().value();
33+
}
34+
if (config.recordChangeDescriptions().has_value()) {
35+
_config.recordChangeDescriptions = config.recordChangeDescriptions().value();
36+
}
37+
}
38+
39+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getReloadAndProfileConfig)
40+
{
41+
return @{
42+
@"shouldReloadAndProfile" : @(_config.shouldReloadAndProfile),
43+
@"recordChangeDescriptions" : @(_config.recordChangeDescriptions),
44+
};
45+
}
46+
47+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
48+
(const facebook::react::ObjCTurboModule::InitParams &)params
49+
{
50+
return std::make_shared<facebook::react::NativeReactDevToolsRuntimeSettingsModuleSpecJSI>(params);
51+
}
52+
53+
@end
54+
55+
Class RCTDevToolsRuntimeSettingsCls(void)
56+
{
57+
return RCTDevToolsRuntimeSettingsModule.class;
58+
}

packages/react-native/ReactAndroid/api/ReactAndroid.api

+6
Original file line numberDiff line numberDiff line change
@@ -3373,6 +3373,12 @@ public final class com/facebook/react/modules/devloading/DevLoadingModule : com/
33733373
public final class com/facebook/react/modules/devloading/DevLoadingModule$Companion {
33743374
}
33753375

3376+
public final class com/facebook/react/modules/devtoolsruntimesettings/ReactDevToolsRuntimeSettingsModule : com/facebook/fbreact/specs/NativeReactDevToolsRuntimeSettingsModuleSpec {
3377+
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
3378+
public fun getReloadAndProfileConfig ()Lcom/facebook/react/bridge/WritableMap;
3379+
public fun setReloadAndProfileConfig (Lcom/facebook/react/bridge/ReadableMap;)V
3380+
}
3381+
33763382
public class com/facebook/react/modules/dialog/AlertFragment : androidx/fragment/app/DialogFragment, android/content/DialogInterface$OnClickListener {
33773383
public fun <init> ()V
33783384
public fun <init> (Lcom/facebook/react/modules/dialog/DialogModule$AlertFragmentListener;Landroid/os/Bundle;)V

packages/react-native/ReactAndroid/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ val preparePrefab by
106106
Pair("../ReactCommon/cxxreact/", "cxxreact/"),
107107
// react_featureflags
108108
Pair("../ReactCommon/react/featureflags/", "react/featureflags/"),
109+
// react_devtoolsruntimesettings
110+
Pair(
111+
"../ReactCommon/react/devtoolsruntimesettings/",
112+
"react/devtoolsruntimesettings/"),
109113
// react_render_animations
110114
Pair(
111115
"../ReactCommon/react/renderer/animations/",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.modules.devtoolsruntimesettings
9+
10+
import com.facebook.fbreact.specs.NativeReactDevToolsRuntimeSettingsModuleSpec
11+
import com.facebook.jni.annotations.DoNotStripAny
12+
import com.facebook.react.bridge.Arguments
13+
import com.facebook.react.bridge.ReactApplicationContext
14+
import com.facebook.react.bridge.ReadableMap
15+
import com.facebook.react.bridge.WritableMap
16+
import com.facebook.react.module.annotations.ReactModule
17+
18+
private class Settings {
19+
var shouldReloadAndProfile: Boolean = false
20+
var recordChangeDescriptions: Boolean = false
21+
}
22+
23+
@DoNotStripAny
24+
@ReactModule(name = NativeReactDevToolsRuntimeSettingsModuleSpec.NAME)
25+
public class ReactDevToolsRuntimeSettingsModule(reactContext: ReactApplicationContext?) :
26+
NativeReactDevToolsRuntimeSettingsModuleSpec(reactContext) {
27+
28+
// static to persist across Turbo Module reloads
29+
private companion object {
30+
private val settings = Settings()
31+
}
32+
33+
override fun setReloadAndProfileConfig(map: ReadableMap) {
34+
if (map.hasKey("shouldReloadAndProfile")) {
35+
settings.shouldReloadAndProfile = map.getBoolean("shouldReloadAndProfile")
36+
}
37+
if (map.hasKey("recordChangeDescriptions")) {
38+
settings.recordChangeDescriptions = map.getBoolean("recordChangeDescriptions")
39+
}
40+
}
41+
42+
override fun getReloadAndProfileConfig(): WritableMap {
43+
val map = Arguments.createMap()
44+
map.putBoolean("shouldReloadAndProfile", settings.shouldReloadAndProfile)
45+
map.putBoolean("recordChangeDescriptions", settings.recordChangeDescriptions)
46+
return map
47+
}
48+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.facebook.react.modules.camera.ImageStoreManager;
2929
import com.facebook.react.modules.clipboard.ClipboardModule;
3030
import com.facebook.react.modules.devloading.DevLoadingModule;
31+
import com.facebook.react.modules.devtoolsruntimesettings.ReactDevToolsRuntimeSettingsModule;
3132
import com.facebook.react.modules.dialog.DialogModule;
3233
import com.facebook.react.modules.fresco.FrescoModule;
3334
import com.facebook.react.modules.i18nmanager.I18nManagerModule;
@@ -88,6 +89,7 @@
8889
NetworkingModule.class,
8990
PermissionsModule.class,
9091
ReactDevToolsSettingsManagerModule.class,
92+
ReactDevToolsRuntimeSettingsModule.class,
9193
ShareModule.class,
9294
SoundManagerModule.class,
9395
StatusBarModule.class,
@@ -156,6 +158,8 @@ public MainReactPackage(MainPackageConfig config) {
156158
return new WebSocketModule(context);
157159
case ReactDevToolsSettingsManagerModule.NAME:
158160
return new ReactDevToolsSettingsManagerModule(context);
161+
case ReactDevToolsRuntimeSettingsModule.NAME:
162+
return new ReactDevToolsRuntimeSettingsModule(context);
159163
default:
160164
return null;
161165
}
@@ -302,6 +306,7 @@ private ReactModuleInfoProvider fallbackForMissingClass() {
302306
NetworkingModule.class,
303307
PermissionsModule.class,
304308
ReactDevToolsSettingsManagerModule.class,
309+
ReactDevToolsRuntimeSettingsModule.class,
305310
ShareModule.class,
306311
StatusBarModule.class,
307312
SoundManagerModule.class,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
cmake_minimum_required(VERSION 3.13)
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
9+
add_compile_options(
10+
-fexceptions
11+
-frtti
12+
-std=c++20
13+
-Wall
14+
-Wpedantic)
15+
16+
add_library(react_devtoolsruntimesettingscxx INTERFACE)
17+
18+
target_include_directories(react_devtoolsruntimesettingscxx INTERFACE .)
19+
20+
target_link_libraries(react_devtoolsruntimesettingscxx
21+
jsi
22+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "DevToolsRuntimeSettings.h"
9+
10+
namespace facebook::react {
11+
12+
void DevToolsRuntimeSettings::setReloadAndProfileConfig(
13+
NativePartialReloadAndProfileConfig config) {
14+
if (config.shouldReloadAndProfile.has_value()) {
15+
_config.shouldReloadAndProfile = config.shouldReloadAndProfile.value();
16+
}
17+
if (config.shouldReloadAndProfile.has_value()) {
18+
_config.recordChangeDescriptions = config.recordChangeDescriptions.value();
19+
}
20+
};
21+
22+
NativeReloadAndProfileConfig
23+
DevToolsRuntimeSettings::getReloadAndProfileConfig() const {
24+
return _config;
25+
};
26+
27+
} // namespace facebook::react
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h>
11+
12+
namespace facebook::react {
13+
14+
using NativePartialReloadAndProfileConfig =
15+
NativeReactDevToolsRuntimeSettingsModulePartialReloadAndProfileConfig<
16+
std::optional<bool>,
17+
std::optional<bool>>;
18+
19+
template <>
20+
struct Bridging<NativePartialReloadAndProfileConfig>
21+
: NativeReactDevToolsRuntimeSettingsModulePartialReloadAndProfileConfigBridging<
22+
NativePartialReloadAndProfileConfig> {};
23+
24+
using NativeReloadAndProfileConfig =
25+
NativeReactDevToolsRuntimeSettingsModuleReloadAndProfileConfig<bool, bool>;
26+
27+
template <>
28+
struct Bridging<NativeReloadAndProfileConfig>
29+
: NativeReactDevToolsRuntimeSettingsModuleReloadAndProfileConfigBridging<
30+
NativeReloadAndProfileConfig> {};
31+
32+
class DevToolsRuntimeSettings {
33+
public:
34+
// static to persist across Turbo Module reloads
35+
static DevToolsRuntimeSettings& getInstance() {
36+
static DevToolsRuntimeSettings instance;
37+
return instance;
38+
}
39+
40+
private:
41+
NativeReloadAndProfileConfig _config;
42+
43+
DevToolsRuntimeSettings() : _config() {}
44+
45+
public:
46+
~DevToolsRuntimeSettings() = default;
47+
DevToolsRuntimeSettings(const DevToolsRuntimeSettings&) = delete;
48+
DevToolsRuntimeSettings(DevToolsRuntimeSettings&&) = delete;
49+
void operator=(const DevToolsRuntimeSettings&) = delete;
50+
void operator=(DevToolsRuntimeSettings&&) = delete;
51+
52+
void setReloadAndProfileConfig(NativePartialReloadAndProfileConfig config);
53+
NativeReloadAndProfileConfig getReloadAndProfileConfig() const;
54+
};
55+
56+
} // namespace facebook::react

packages/react-native/ReactCommon/react/nativemodule/defaults/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ target_include_directories(react_nativemodule_defaults PUBLIC ${REACT_COMMON_DIR
2121

2222
target_link_libraries(react_nativemodule_defaults
2323
react_nativemodule_dom
24+
react_nativemodule_devtoolsruntimesettings
2425
react_nativemodule_featureflags
2526
react_nativemodule_microtasks
2627
react_nativemodule_idlecallbacks

packages/react-native/ReactCommon/react/nativemodule/defaults/DefaultTurboModules.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include <react/nativemodule/idlecallbacks/NativeIdleCallbacks.h>
1212
#include <react/nativemodule/microtasks/NativeMicrotasks.h>
1313

14+
#ifdef HERMES_ENABLE_DEBUGGER
15+
#include <react/nativemodule/devtoolsruntimesettings/DevToolsRuntimeSettingsModule.h>
16+
#endif
17+
1418
namespace facebook::react {
1519

1620
/* static */ std::shared_ptr<TurboModule> DefaultTurboModules::getTurboModule(
@@ -32,6 +36,12 @@ namespace facebook::react {
3236
return std::make_shared<NativeDOM>(jsInvoker);
3337
}
3438

39+
#ifdef HERMES_ENABLE_DEBUGGER
40+
if (name == DevToolsRuntimeSettingsModule::kModuleName) {
41+
return std::make_shared<DevToolsRuntimeSettingsModule>(jsInvoker);
42+
}
43+
#endif
44+
3545
return nullptr;
3646
}
3747

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
cmake_minimum_required(VERSION 3.13)
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
9+
add_compile_options(
10+
-fexceptions
11+
-frtti
12+
-std=c++20
13+
-Wall
14+
-Wpedantic
15+
-DLOG_TAG=\"ReactNative\")
16+
17+
file(GLOB react_nativemodule_devtoolsruntimesettings_SRC CONFIGURE_DEPENDS *.cpp)
18+
add_library(react_nativemodule_devtoolsruntimesettings OBJECT ${react_nativemodule_devtoolsruntimesettings_SRC})
19+
20+
target_include_directories(react_nativemodule_devtoolsruntimesettings PUBLIC ${REACT_COMMON_DIR})
21+
22+
target_link_libraries(react_nativemodule_devtoolsruntimesettings
23+
react_devtoolsruntimesettingscxx
24+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "DevToolsRuntimeSettingsModule.h"
9+
#include "Plugins.h"
10+
11+
std::shared_ptr<facebook::react::TurboModule>
12+
ReactDevToolsRuntimeSettingsModuleProvider(
13+
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
14+
return std::make_shared<facebook::react::DevToolsRuntimeSettingsModule>(
15+
std::move(jsInvoker));
16+
}
17+
18+
namespace facebook::react {
19+
20+
DevToolsRuntimeSettingsModule::DevToolsRuntimeSettingsModule(
21+
std::shared_ptr<CallInvoker> jsInvoker)
22+
: NativeReactDevToolsRuntimeSettingsModuleCxxSpec(std::move(jsInvoker)) {}
23+
24+
void DevToolsRuntimeSettingsModule::setReloadAndProfileConfig(
25+
jsi::Runtime& /*rt*/,
26+
NativePartialReloadAndProfileConfig config) {
27+
DevToolsRuntimeSettings::getInstance().setReloadAndProfileConfig(config);
28+
};
29+
30+
NativeReloadAndProfileConfig
31+
DevToolsRuntimeSettingsModule::getReloadAndProfileConfig(jsi::Runtime& /*rt*/) {
32+
return DevToolsRuntimeSettings::getInstance().getReloadAndProfileConfig();
33+
};
34+
35+
} // namespace facebook::react

0 commit comments

Comments
 (0)