Skip to content

Commit d3b937f

Browse files
janicduplessisfacebook-github-bot
authored andcommitted
Make sure LogBox is not included in production bundles (#28984)
Summary: I was doing some bundle inspection and noticed the LogBox module was included. It does amount to around 15kb so I think it is worth making sure it is not there. To fix it I moved some imports to require inside __DEV__ blocks to make sure metro is able to remove these imports. ## Changelog [General] [Fixed] - Make sure LogBox is not included in production bundles Pull Request resolved: #28984 Test Plan: Tested using react-native-bundle-visualizer and made sure nothing from LogBox was included in the bundle after these changes. Reviewed By: TheSavior Differential Revision: D21794466 Pulled By: rickhanlonii fbshipit-source-id: 6cb0c0a89633e9850019bd61478c35e9c21638dc
1 parent ceb6c3d commit d3b937f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Libraries/Core/ExceptionsManager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'use strict';
1212

1313
import type {ExtendedError} from './Devtools/parseErrorStack';
14-
import * as LogBoxData from '../LogBox/Data/LogBoxData';
1514
import type {ExceptionData} from './NativeExceptionsManager';
1615

1716
class SyntheticError extends Error {
@@ -104,7 +103,8 @@ function reportException(
104103
console.error(data.message);
105104
}
106105

107-
if (isHandledByLogBox) {
106+
if (__DEV__ && isHandledByLogBox) {
107+
const LogBoxData = require('../LogBox/Data/LogBoxData');
108108
LogBoxData.addException({
109109
...data,
110110
isComponentError: !!e.isComponentError,

Libraries/LogBox/LogBox.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
import Platform from '../Utilities/Platform';
1414
import RCTLog from '../Utilities/RCTLog';
15-
import * as LogBoxData from './Data/LogBoxData';
16-
import {parseLogBoxLog, parseInterpolation} from './Data/parseLogBoxLog';
1715

1816
import type {IgnorePattern} from './Data/LogBoxData';
1917

@@ -23,6 +21,9 @@ let LogBox;
2321
* LogBox displays logs in the app.
2422
*/
2523
if (__DEV__) {
24+
const LogBoxData = require('./Data/LogBoxData');
25+
const {parseLogBoxLog, parseInterpolation} = require('./Data/parseLogBoxLog');
26+
2627
// LogBox needs to insert itself early,
2728
// in order to access the component stacks appended by React DevTools.
2829
const {error, warn} = console;

0 commit comments

Comments
 (0)