-
-
Notifications
You must be signed in to change notification settings - Fork 62
Closed
Description
The findOne helper is meant to recursively find an element in a tree that passes the provided test function. However, the implementation is written such that the function will return the result of the search through the first node that has any children, regardless of whether a passing element was found in that branch.
See the implementation here. The problem occurs on Line 115.
Consider the tree:
<div>
<p>Paragraph</p>
<b>Text</b>
</div>When searching for the paragraph, it's successful:
const found = findOne(el => el.tagName === "p", nodes)
console.log(found)
// Element { ... }When searching for the bold tag, however, it fails:
const found = findOne(el => el.tagName === "b", nodes)
console.log(found)
// undefinedThis happens because the paragraph has children, so the current implementation of findOne enters that recursion branch and returns regardless of the result.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels