From a06153c52aa6bbc415fa5a66d4dc6aba223fbce1 Mon Sep 17 00:00:00 2001 From: Sean Tarzy Date: Tue, 24 Mar 2026 17:43:56 -0700 Subject: [PATCH] Use lazy TurboModule lookup for Clipboard in LogBoxInspector (#56199) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56199 D95277489 added a Copy button to LogBoxInspector that imports `Clipboard`, which calls `TurboModuleRegistry.getEnforcing('Clipboard')` at module load time. In environments where the native Clipboard module is not available (e.g., Fantom integration tests), this throws and crashes the entire test file (`LogBox-itest.fb.js`). Replace the static `Clipboard` import with a lazy `TurboModuleRegistry.get()` call at invocation time, which returns `null` when the module is unavailable instead of throwing. Changelog: [internal][fixed][LogBox] - Fix crash when Clipboard module is unavailable Reviewed By: NickGerleman Differential Revision: D97008263 fbshipit-source-id: 5720ff8fdeb3f187aa7be77b13dc839c02469751 --- packages/react-native/Libraries/LogBox/UI/LogBoxInspector.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/LogBox/UI/LogBoxInspector.js b/packages/react-native/Libraries/LogBox/UI/LogBoxInspector.js index f76143a3e07..646294b40f5 100644 --- a/packages/react-native/Libraries/LogBox/UI/LogBoxInspector.js +++ b/packages/react-native/Libraries/LogBox/UI/LogBoxInspector.js @@ -8,7 +8,6 @@ * @format */ -import Clipboard from '../../Components/Clipboard/Clipboard'; import Keyboard from '../../Components/Keyboard/Keyboard'; import View from '../../Components/View/View'; import StyleSheet from '../../StyleSheet/StyleSheet'; @@ -98,6 +97,9 @@ export default function LogBoxInspector(props: Props): React.Node { } } + // Lazy-require to avoid crashing in environments where the native + // Clipboard module is unavailable (e.g. Fantom integration tests). + const Clipboard = require('../../Components/Clipboard/Clipboard').default; Clipboard.setString(parts.join('\n')); }