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.
https://codepen.io/MichaelWest22/pen/yyBwPww
https://codepen.io/MichaelWest22/pen/XJrGzxv
In the old idiomorph there is extra bestMatch code that handles outerHTML swaps. It handles the situation where you are replacing a single node with possibly multiple nodes via the outerHTML morph mode and it find the most id'ed node and swaps that with the single node. This works because we know there is just one node in the old content so finding the best match for a single node is a simple routine. When trying to integrate this with the new Algorithm I found that it was possible to make this feature more generic. By finding the last node in the old child nodes that has id content at each tree level we can apply the original bestMatch checking just to this last node with id's. It may be possible to do this same kind of logic every time but it would get far to complex and slow so instead we can apply it just to the last node with id's. We know this node is the last one we care about so can then check all remaining new nodes for the very best match easily. To do this we just scan for the last id with node at the start of the morphChildren loop and apply an extra check at the start of findBestMatch which will cause it to insert new child nodes that are not the best match till the best match shows up.
Added some tests to show off where it applies and also the above two codepen's show off how it works but this feature only covers off what is kind of an edge case and will often not be needed outside of these edge cases.