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
This commit is contained in:
Sean Tarzy authored and meta-codesync[bot] committed 2026-03-24 17:43:56 -07:00
1 parent 0b1def9ce5
commit a06153c52a
1 file changed
+3 -1
@@ -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'));
}