Skip to content

Commit

Permalink
Fusebox reload-to-profile (Part 2 of 2: JS) (facebook#46905)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#46905

Changelog: [General][Added] - Add support for reload-to-profile in Fusebox (Part 2 of 2: JS)

Reviewed By: hoxyq

Differential Revision: D64077813

fbshipit-source-id: a6d3326d8514f49e47074d21d37e00044ad62fd8
  • Loading branch information
EdmondChuiHW authored and facebook-github-bot committed Oct 16, 2024
1 parent 85f1d9a commit 4df224c
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion packages/react-native/Libraries/Core/setUpReactDevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
'use strict';

import type {Domain} from '../../src/private/debugging/setUpFuseboxReactDevToolsDispatcher';
import type {
PartialReloadAndProfileConfig,
Spec as NativeReactDevToolsRuntimeSettingsModuleSpec,
} from '../../src/private/fusebox/specs/NativeReactDevToolsRuntimeSettingsModule';

if (__DEV__) {
// Register dispatcher on global, which can be used later by Chrome DevTools frontend
Expand All @@ -24,6 +28,8 @@ if (__DEV__) {
const reactDevToolsSettingsManager = require('../../src/private/debugging/ReactDevToolsSettingsManager');
const serializedHookSettings =
reactDevToolsSettingsManager.getGlobalHookSettings();
const maybeReactDevToolsRuntimeSettingsModuleModule =
require('../../src/private/fusebox/specs/NativeReactDevToolsRuntimeSettingsModule').default;

let hookSettings = null;
if (serializedHookSettings != null) {
Expand All @@ -36,8 +42,23 @@ if (__DEV__) {
);
}
}

const reloadAndProfileConfigPersistence =
makeReloadAndProfileConfigPersistence(
maybeReactDevToolsRuntimeSettingsModuleModule,
);

const shouldStartProfilingNow =
reloadAndProfileConfigPersistence?.getReloadAndProfileConfig()
?.shouldReloadAndProfile === true;
const profilingSettings = {
recordChangeDescriptions:
reloadAndProfileConfigPersistence?.getReloadAndProfileConfig()
?.recordChangeDescriptions === true,
recordTimeline: false,
};
// Install hook before React is loaded.
initialize(hookSettings);
initialize(hookSettings, shouldStartProfilingNow, profilingSettings);

// This should be defined in DEV, otherwise error is expected.
const fuseboxReactDevToolsDispatcher =
Expand Down Expand Up @@ -76,6 +97,23 @@ if (__DEV__) {
nativeStyleEditorValidAttributes: Object.keys(ReactNativeStyleAttributes),
resolveRNStyle,
onSettingsUpdated: handleReactDevToolsSettingsUpdate,
isReloadAndProfileSupported:
maybeReactDevToolsRuntimeSettingsModuleModule != null,
isProfiling:
reloadAndProfileConfigPersistence?.getReloadAndProfileConfig()
?.shouldReloadAndProfile === true,
onReloadAndProfile: (recordChangeDescriptions: boolean) => {
reloadAndProfileConfigPersistence?.setReloadAndProfileConfig({
shouldReloadAndProfile: true,
recordChangeDescriptions,
});
},
onReloadAndProfileFlagsReset: () => {
reloadAndProfileConfigPersistence?.setReloadAndProfileConfig({
shouldReloadAndProfile: false,
recordChangeDescriptions: false,
});
},
});
}

Expand Down Expand Up @@ -135,6 +173,23 @@ if (__DEV__) {
),
websocket: ws,
onSettingsUpdated: handleReactDevToolsSettingsUpdate,
isReloadAndProfileSupported:
maybeReactDevToolsRuntimeSettingsModuleModule != null,
isProfiling:
reloadAndProfileConfigPersistence?.getReloadAndProfileConfig()
?.shouldReloadAndProfile === true,
onReloadAndProfile: (recordChangeDescriptions: boolean) => {
reloadAndProfileConfigPersistence?.setReloadAndProfileConfig({
shouldReloadAndProfile: true,
recordChangeDescriptions,
});
},
onReloadAndProfileFlagsReset: () => {
reloadAndProfileConfigPersistence?.setReloadAndProfileConfig({
shouldReloadAndProfile: false,
recordChangeDescriptions: false,
});
},
});
}
}
Expand Down Expand Up @@ -166,3 +221,20 @@ if (__DEV__) {
);
connectToWSBasedReactDevToolsFrontend(); // Try connecting once on load
}

function makeReloadAndProfileConfigPersistence(
maybeModule: ?NativeReactDevToolsRuntimeSettingsModuleSpec,
) {
if (maybeModule == null) {
return;
}

return {
setReloadAndProfileConfig(config: PartialReloadAndProfileConfig): void {
maybeModule.setReloadAndProfileConfig(config);
},
getReloadAndProfileConfig() {
return maybeModule.getReloadAndProfileConfig();
},
};
}

0 comments on commit 4df224c

Please sign in to comment.