Describe the bug
Preact unnecessarily removes and adds the DOM nodes that it finds after HTML comments during hydration.
<div id="root">
<div>I'm going to be preserved in the DOM</div>
<!-- I'm a comment, so I'll be removed, which is also fine -->
<div>I'll be removed and added back again</div>
</div>
To Reproduce
I reproduced the bug in this repository: https://github.com/luisherranz/preact-comments-hydration-bug (Open with Stackblitz Codeflow)
And this is a branch with a Mutation Observer added to the current hydration tests.
Steps to reproduce the behavior:
- Add a comment to the SSR'ed HTML
- Monitor changes to the DOM
- Hydrate it with Preact
- The nodes after the HTML comment are removed and added again
There is a video with a longer explanation on this other issue.
Expected behavior
Preact should remove the comments, but it should preserve the rest of the DOM nodes.