Skip to content

Instantly share code, notes, and snippets.

@stonexer
Last active March 14, 2020 15:05
Show Gist options
  • Save stonexer/abb65c7b911f3a558959dd39c282c054 to your computer and use it in GitHub Desktop.
Save stonexer/abb65c7b911f3a558959dd39c282c054 to your computer and use it in GitHub Desktop.
function countReactFibers() {
const rootContainer = document.getElementById('root');
const root = rootContainer._reactRootContainer;
const internalRoot = root._internalRoot;
let fiberCount = 0;
let elementCount = 0;
function travelFibers(fiberNode) {
console.log(fiberNode);
if (typeof fiberNode.elementType === 'string') {
elementCount += 1;
}
if (typeof fiberNode.elementType === 'function') {
fiberCount += 1;
}
if (fiberNode.child) {
travelFibers(fiberNode.child);
}
if (fiberNode.sibling) {
travelFibers(fiberNode.sibling);
}
}
travelFibers(internalRoot.current);
console.info('Fiber:', fiberCount);
console.info('ElementCount:', elementCount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment