Last active
March 14, 2020 15:05
-
-
Save stonexer/abb65c7b911f3a558959dd39c282c054 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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