Iterate through the live NodeList instead of copying to an array in $generateNodesFromDOM #4164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The HTML deserialization design is partially predicated on the user having the ability to manipulate the DOM tree in the conversion functions - this provides virtually limitless flexibility in how incoming HTML can be processed.
Previously, we copied the DOM nodes at the top level to an array, then iterated through that to initiate the HTML -> Lexical transformation. This works fine in most cases, but it can cause an issue in a couple of edge cases where you're trying to combine sibling DOM nodes into a single LexicalNode. There's no way to prevent those sibling nodes from being processed, since they have already been copied to an array, removing them from the DOM does nothing.
Alternative proposed solution was to mark the nodes as "processed" and then ignore them in the next pass, but this doesn't prevent their children from being processed. Also considered allowing the conversion to return "true" to stop further processing, but finally decided that this is just a bug.