Strip complex values from ReactPerf.printDOM() output
Fixes #6288
Dan Abramov committed
Mar 17, 2016 at 21:23 UTC
b6547734c62773cd57358d5fd4e45f58ab81f81a
2 files changed
+27
-1
src/test/ReactDefaultPerf.js
+12
-1
@@ -52,6 +52,17 @@ function getID(inst) {
52
}
53
}
54
55
+function stripComplexValues(key, value) {
56
+ if (typeof value !== 'object' || Array.isArray(value) || value == null) {
57
+ return value;
58
+ }
59
+ var prototype = Object.getPrototypeOf(value);
60
+ if (!prototype || prototype === Object.prototype) {
61
+ return value;
62
+ }
63
+ return '<not serializable>';
64
+}
65
+
66
// This implementation of ReactPerf is going away some time mid 15.x.
67
// While we plan to keep most of the API, the actual format of measurements
68
// will change dramatically. To signal this, we wrap them into an opaque-ish
@@ -174,7 +185,7 @@ var ReactDefaultPerf = {
185
var result = {};
186
result[DOMProperty.ID_ATTRIBUTE_NAME] = item.id;
187
result.type = item.type;
177
- result.args = JSON.stringify(item.args);
188
+ result.args = JSON.stringify(item.args, stripComplexValues);
189
return result;
190
}));
191
console.log(
src/test/__tests__/ReactDefaultPerf-test.js
+15
@@ -237,6 +237,21 @@ describe('ReactDefaultPerf', function() {
237
expect(summary).toEqual([]);
238
});
239
240
+ it('should print a table after calling printOperations', function() {
241
+ var container = document.createElement('div');
242
+ var measurements = measure(() => {
243
+ ReactDOM.render(<Div>hey</Div>, container);
244
+ });
245
+ spyOn(console, 'table');
246
+ ReactDefaultPerf.printOperations(measurements);
247
+ expect(console.table.calls.length).toBe(1);
248
+ expect(console.table.argsForCall[0][0]).toEqual([{
249
+ 'data-reactid': '',
250
+ type: 'set innerHTML',
251
+ args: '{"node":"<not serializable>","children":[],"html":null,"text":null}',
252
+ }]);
253
+ });
254
+
255
it('warns once when using getMeasurementsSummaryMap', function() {
256
var measurements = measure(() => {});
257
spyOn(console, 'error');