Skip to content

Commit 285e661

Browse files
committed
dumpTree helper for debugging
It is helpful to be able to dump information about the current tree for debugging issues in unit tests.
1 parent 97cd8e1 commit 285e661

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/renderers/noop/ReactNoop.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
'use strict';
2121

22+
import type { Fiber } from 'ReactFiber';
23+
2224
var ReactFiberReconciler = require('ReactFiberReconciler');
2325

2426
var scheduledHighPriCallback = null;
@@ -83,6 +85,35 @@ var ReactNoop = {
8385
ReactNoop.flushLowPri();
8486
},
8587

88+
// Logs the current state of the tree.
89+
dumpTree() {
90+
if (!root) {
91+
console.log('Nothing rendered yet.');
92+
return;
93+
}
94+
let fiber : Fiber = (root.stateNode : any).current;
95+
let depth = 0;
96+
while (fiber) {
97+
console.log(' '.repeat(depth) + '- ' + (fiber.type ? fiber.type.name || fiber.type : '[root]'), '[' + fiber.pendingWorkPriority + (fiber.pendingProps ? '*' : '') + ']');
98+
if (fiber.child) {
99+
fiber = fiber.child;
100+
depth++;
101+
continue;
102+
} else {
103+
while (!fiber.sibling) {
104+
if (!fiber.parent) {
105+
return;
106+
} else {
107+
// $FlowFixMe: This downcast is not safe. It is intentionally an error.
108+
fiber = fiber.parent;
109+
}
110+
depth--;
111+
}
112+
fiber = fiber.sibling;
113+
}
114+
}
115+
},
116+
86117
};
87118

88119
module.exports = ReactNoop;

0 commit comments

Comments
 (0)