Skip to content

Hydration removes and add nodes again when there are HTML comments just before them #3767

@luisherranz

Description

@luisherranz
  • Check if updating to the latest Preact version resolves the issue

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:

  1. Add a comment to the SSR'ed HTML
  2. Monitor changes to the DOM
  3. Hydrate it with Preact
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions