Skip to content

Commit

Permalink
Make sure LogBox is not included in production bundles (#28984)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Jun 3, 2020
1 parent ceb6c3d commit d3b937f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Libraries/Core/ExceptionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'use strict';

import type {ExtendedError} from './Devtools/parseErrorStack';
import * as LogBoxData from '../LogBox/Data/LogBoxData';
import type {ExceptionData} from './NativeExceptionsManager';

class SyntheticError extends Error {
Expand Down Expand Up @@ -104,7 +103,8 @@ function reportException(
console.error(data.message);
}

if (isHandledByLogBox) {
if (__DEV__ && isHandledByLogBox) {
const LogBoxData = require('../LogBox/Data/LogBoxData');
LogBoxData.addException({
...data,
isComponentError: !!e.isComponentError,
Expand Down
5 changes: 3 additions & 2 deletions Libraries/LogBox/LogBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

import Platform from '../Utilities/Platform';
import RCTLog from '../Utilities/RCTLog';
import * as LogBoxData from './Data/LogBoxData';
import {parseLogBoxLog, parseInterpolation} from './Data/parseLogBoxLog';

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

Expand All @@ -23,6 +21,9 @@ let LogBox;
* LogBox displays logs in the app.
*/
if (__DEV__) {
const LogBoxData = require('./Data/LogBoxData');
const {parseLogBoxLog, parseInterpolation} = require('./Data/parseLogBoxLog');

// LogBox needs to insert itself early,
// in order to access the component stacks appended by React DevTools.
const {error, warn} = console;
Expand Down

0 comments on commit d3b937f

Please sign in to comment.