Skip to content

Commit a06153c

Browse files
seantarzymeta-codesync[bot]
authored andcommitted
Use lazy TurboModule lookup for Clipboard in LogBoxInspector (#56199)
Summary: Pull Request resolved: #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
1 parent 0b1def9 commit a06153c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/react-native/Libraries/LogBox/UI/LogBoxInspector.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @format
99
*/
1010

11-
import Clipboard from '../../Components/Clipboard/Clipboard';
1211
import Keyboard from '../../Components/Keyboard/Keyboard';
1312
import View from '../../Components/View/View';
1413
import StyleSheet from '../../StyleSheet/StyleSheet';
@@ -98,6 +97,9 @@ export default function LogBoxInspector(props: Props): React.Node {
9897
}
9998
}
10099

100+
// Lazy-require to avoid crashing in environments where the native
101+
// Clipboard module is unavailable (e.g. Fantom integration tests).
102+
const Clipboard = require('../../Components/Clipboard/Clipboard').default;
101103
Clipboard.setString(parts.join('\n'));
102104
}
103105

0 commit comments

Comments
 (0)