question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • 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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
luisherranzcommented, Oct 17, 2022

I’m going to close this issue as this works as expected, and we will manually remove the HTML comments during our DOM -> vDOM step. I’ll keep an eye on what you release for streaming in case we can adopt it in the future!

0reactions
luisherranzcommented, Oct 17, 2022

the pending areas need to be marked with HTML comments

Oh, interesting (and exciting) 🙂

What’s your idea about that part? (for example, is the idea to keep vnode representations of those HTML comments in the vdom while the rest of the HTML is streamed?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Initial rendering remove all nodes from server side ... - GitHub
When load the page in the first time or click the "refresh" button in browser, the client side js is going to remove...
Read more >
Hydrating text content from Server-Side Rendering | Tan Li Hau
So, when React tries to hydrate the div from SSR, it starts with comparing all the props from the React element and the...
Read more >
Understand and solve hydration errors in Vue.js - sum.cumo
As long as only the content of text nodes/attributes is affected, that is, no nodes are added or removed, hydration errors do not...
Read more >
Why Efficient Hydration in JavaScript Frameworks is so ...
Most frameworks hydration ready code is larger than their typical client code because ultimately it needs to do both things. It might only...
Read more >
How to render a HTML comment in React? - Stack Overflow
For one thing, it doesn't address the core issue; the result is four nodes (a comment node, two element nodes, and then a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found