Skip to content

Commit

Permalink
Merge pull request #6289 from gaearon/strip-circular-refs
Browse files Browse the repository at this point in the history
Strip complex values from ReactPerf.printDOM() output
  • Loading branch information
gaearon committed Mar 18, 2016
2 parents d138b28 + b654773 commit 67f8524
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/test/ReactDefaultPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions src/test/__tests__/ReactDefaultPerf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 67f8524

Please sign in to comment.