Bring RNDT shell to front when paused on breakpoint (#51748)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51748

Changelog: [Internal]

Implements the first RNDT shell-specific feature based on https://github.com/facebook/react-native-devtools-frontend/pull/168 - namely, the ability for RNDT to foreground itself when certain events occur. This is most noticeable when pausing on a breakpoint.

Reviewed By: huntie, vzaidman

Differential Revision: D75795689

fbshipit-source-id: a073bf8ea96ba70d835007f5af6069d49a693d81
This commit is contained in:
Moti Zilberman
2025-06-03 06:37:35 -07:00
committed by Facebook GitHub Bot
parent 75be907aa9
commit ab2c81faeb
2 changed files with 56 additions and 1 deletions
@@ -0,0 +1,41 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
const {contextBridge, ipcRenderer} = require('electron');
contextBridge.executeInMainWorld({
func: ipcDevTools => {
let didDecorateInspectorFrontendHostInstance = false;
// reactNativeDecorateInspectorFrontendHostInstance was introduced in
// https://github.com/facebook/react-native-devtools-frontend/pull/168
globalThis.reactNativeDecorateInspectorFrontendHostInstance =
InspectorFrontendHostInstance => {
didDecorateInspectorFrontendHostInstance = true;
InspectorFrontendHostInstance.bringToFront = () => {
ipcDevTools.bringToFront();
};
};
document.addEventListener('DOMContentLoaded', () => {
if (!didDecorateInspectorFrontendHostInstance) {
console.error(
'reactNativeDecorateInspectorFrontendHostInstance was not called at startup. ' +
'This version of the DevTools frontend may not be compatible with @react-native/debugger-shell.',
);
}
});
},
args: [
{
bringToFront() {
ipcRenderer.send('bringToFront');
},
},
],
});