refactor(core): add actionable hydration mismatch hints - #68529
Conversation
Adds targeted hints for known browser HTML normalization cases that alter the DOM before Angular hydration. Closes angular#56392
thePunderWoman
left a comment
There was a problem hiding this comment.
When we were building out hydration, we explicitly didn't want to add in DOM validation like this, and I think this is strictly still true. The point of the original bug was not to identify these cases, but have better messages that point to the exact locations where the failure occurs. So IMHO this is too far down the DOM validation path.
|
Honestly, I could not think of a better solution at this moment without directly tying it to the browser’s behavior. The current diagnostic message is descriptive enough to indicate where the hydration mismatch happens, but in my opinion it does not clearly explain the why behind it. My understanding is that, without considering how the browser parses and normalizes the HTML, there is no reliable way to explain the exact cause in these cases. Of course, I also understand that the DOM could have been changed by something external, such as browser extensions or third-party scripts, so the message cannot be completely certain. I'm going to close this for now, as it's possibly not something we want and we might revisit it in the future. |
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds targeted hints for known browser HTML normalization cases that alter the DOM before Angular hydration.
Closes #56392
What is the current behavior?
Currently, the message may be somewhat generic and not indicate the real or complete cause of the problem.
What is the new behavior?
Missing explicit
<tbody>Spec :
When a
<tr>is written directly under<table>, the parser cancreate the missing table body section before Angular hydrates.
See: https://html.spec.whatwg.org/multipage/syntax.html#optional-tags
Missing explicit
<colgroup>Spec :
When a
<col>is written directly under<table>, the parser cancreate the missing column group before Angular hydrates.
See: https://html.spec.whatwg.org/multipage/syntax.html#optional-tags
Nested anchors
Spec:
Parser:
Nested links are invalid and the parser can close/restructure the
outer anchor before Angular hydrates.
See: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element
See: https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody
Block content inside
<p>Spec :
The parser closes the paragraph before inserting the block, so
the block becomes a sibling instead of a child.
See: https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element
Nested buttons
Spec :
Parser:
When the parser sees the inner
<button>, it closes the currentbutton first, so the buttons become siblings instead of nested nodes.
See: https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element
See: https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody