mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fb8e6610e5
Summary:
This diff improves LogBox performance by not storing and updating logs that are ignored.
Previous we stored all logs, including ignored, as a set. This was so that later, when we show a list of all logs, we would be able to show the ignored logs as well if toggled on. We stored the logs as:
```
const logs = new Set([
{
message: "Not ignored",
ignored: false,
},
{
message: "Ignored",
ignored: true,
},
// 100s more ignored logs
]);
```
But it turns out, we can have hundreds of ignored logs within seconds in some parts of the app. This means we we're re-rendering the LogBoxContainer hundreds of times with a filter on this set to filter out the ignored logs, just to change none of the content.
Now we store as:
```
const logs = new Set([
{
message: "Not ignored",
},
]);
```
Later, when we want to show ignored logs, we'll store these separately.
Changelog: [Internal]
Reviewed By: cpojer
Differential Revision: D18055799
fbshipit-source-id: f5e21f66bb4ab6137d5d3908e8c03e119e3805d5
149 lines
3.4 KiB
JavaScript
149 lines
3.4 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @emails oncall+react_native
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {StackFrame} from '../../../Core/NativeExceptionsManager';
|
|
|
|
jest.mock('../LogBoxSymbolication', () => {
|
|
return {__esModule: true, symbolicate: jest.fn(), deleteStack: jest.fn()};
|
|
});
|
|
|
|
function getLogBoxLog() {
|
|
return new (require('../LogBoxLog')).default(
|
|
{content: '...', substitutions: []},
|
|
createStack(['A', 'B', 'C']),
|
|
'Message category...',
|
|
[{component: 'LogBoxLog', location: 'LogBoxLog.js:1'}],
|
|
);
|
|
}
|
|
|
|
function getLogBoxSymbolication(): {|
|
|
symbolicate: JestMockFn<
|
|
$ReadOnlyArray<Array<StackFrame>>,
|
|
Promise<Array<StackFrame>>,
|
|
>,
|
|
|} {
|
|
return (require('../LogBoxSymbolication'): any);
|
|
}
|
|
|
|
const createStack = methodNames =>
|
|
methodNames.map(methodName => ({
|
|
column: null,
|
|
file: 'file://path/to/file.js',
|
|
lineNumber: 1,
|
|
methodName,
|
|
}));
|
|
|
|
describe('LogBoxLog', () => {
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
|
|
getLogBoxSymbolication().symbolicate.mockImplementation(async stack =>
|
|
createStack(stack.map(frame => `S(${frame.methodName})`)),
|
|
);
|
|
});
|
|
|
|
it('creates a LogBoxLog object', () => {
|
|
const log = getLogBoxLog();
|
|
|
|
expect(log.message).toEqual({content: '...', substitutions: []});
|
|
expect(log.stack).toEqual(createStack(['A', 'B', 'C']));
|
|
expect(log.category).toEqual('Message category...');
|
|
expect(log.componentStack).toEqual([
|
|
{component: 'LogBoxLog', location: 'LogBoxLog.js:1'},
|
|
]);
|
|
});
|
|
|
|
it('increments LogBoxLog count', () => {
|
|
const log = getLogBoxLog();
|
|
|
|
expect(log.count).toEqual(1);
|
|
|
|
log.incrementCount();
|
|
|
|
expect(log.count).toEqual(2);
|
|
});
|
|
|
|
it('starts without a symbolicated stack', () => {
|
|
const log = getLogBoxLog();
|
|
|
|
expect(log.symbolicated).toEqual({
|
|
error: null,
|
|
stack: null,
|
|
status: 'NONE',
|
|
});
|
|
});
|
|
|
|
it('updates when symbolication is in progress', () => {
|
|
const log = getLogBoxLog();
|
|
|
|
const callback = jest.fn();
|
|
log.symbolicate(callback);
|
|
|
|
expect(callback.mock.calls.length).toBe(1);
|
|
expect(log.symbolicated).toEqual({
|
|
error: null,
|
|
stack: null,
|
|
status: 'PENDING',
|
|
});
|
|
});
|
|
|
|
it('updates when symbolication finishes', () => {
|
|
const log = getLogBoxLog();
|
|
|
|
const callback = jest.fn();
|
|
log.symbolicate(callback);
|
|
|
|
jest.runAllTicks();
|
|
|
|
expect(callback.mock.calls.length).toBe(2);
|
|
expect(log.symbolicated).toEqual({
|
|
error: null,
|
|
stack: createStack(['S(A)', 'S(B)', 'S(C)']),
|
|
status: 'COMPLETE',
|
|
});
|
|
});
|
|
|
|
it('updates when symbolication fails', () => {
|
|
const error = new Error('...');
|
|
getLogBoxSymbolication().symbolicate.mockImplementation(async stack => {
|
|
throw error;
|
|
});
|
|
|
|
const log = getLogBoxLog();
|
|
|
|
const callback = jest.fn();
|
|
log.symbolicate(callback);
|
|
|
|
jest.runAllTicks();
|
|
|
|
expect(callback.mock.calls.length).toBe(2);
|
|
expect(log.symbolicated).toEqual({
|
|
error,
|
|
stack: null,
|
|
status: 'FAILED',
|
|
});
|
|
});
|
|
|
|
it('does not update aborted requests', () => {
|
|
const log = getLogBoxLog();
|
|
|
|
const callback = jest.fn();
|
|
const request = log.symbolicate(callback);
|
|
request.abort();
|
|
|
|
jest.runAllTicks();
|
|
|
|
expect(callback.mock.calls.length).toBe(1);
|
|
});
|
|
});
|