Strip complex values from ReactPerf.printDOM() output

Fixes #6288
This commit is contained in:
Dan Abramov
2016-03-17 21:23:41 +00:00
parent 5520c399a6
commit b6547734c6
2 changed files with 27 additions and 1 deletions
+12 -1
View File
@@ -52,6 +52,17 @@ function getID(inst) {
}
}
function stripComplexValues(key, value) {
if (typeof value !== 'object' || Array.isArray(value) || value == null) {
return value;
}
var prototype = Object.getPrototypeOf(value);
if (!prototype || prototype === Object.prototype) {
return value;
}
return '<not serializable>';
}
// This implementation of ReactPerf is going away some time mid 15.x.
// While we plan to keep most of the API, the actual format of measurements
// will change dramatically. To signal this, we wrap them into an opaque-ish
@@ -174,7 +185,7 @@ var ReactDefaultPerf = {
var result = {};
result[DOMProperty.ID_ATTRIBUTE_NAME] = item.id;
result.type = item.type;
result.args = JSON.stringify(item.args);
result.args = JSON.stringify(item.args, stripComplexValues);
return result;
}));
console.log(
@@ -237,6 +237,21 @@ describe('ReactDefaultPerf', function() {
expect(summary).toEqual([]);
});
it('should print a table after calling printOperations', function() {
var container = document.createElement('div');
var measurements = measure(() => {
ReactDOM.render(<Div>hey</Div>, container);
});
spyOn(console, 'table');
ReactDefaultPerf.printOperations(measurements);
expect(console.table.calls.length).toBe(1);
expect(console.table.argsForCall[0][0]).toEqual([{
'data-reactid': '',
type: 'set innerHTML',
args: '{"node":"<not serializable>","children":[],"html":null,"text":null}',
}]);
});
it('warns once when using getMeasurementsSummaryMap', function() {
var measurements = measure(() => {});
spyOn(console, 'error');