Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
fix(gatsby): fix an infinite loop in node child collection #17078
Currently there are cases where a cyclic node graph can cause findChildrenRecursively to hit the limit of the stack. Also, recursive functions are notoriously slow in JS.
I've replaced this with a non-recursive implementation of a pre-order depth first search tree traversal, and also made it keep track of traversed nodes. This will prevent duplicate nodes being found, and also prevent infinite loops with cyclic node trees.
Correct me if I'm wrong - but renaming this method is fine as it is not exported, and all local usages have been fixed.