Repository navigation
fix(mock-doc): treat removed comments as empty content - #6986
Open
thelastbackspace wants to merge 1 commit into
Open
thelastbackspace wants to merge 1 commit into
thelastbackspace wants to merge 1 commit into
Conversation
When removeHtmlComments is set, a comment is dropped from the output but still counted as a child, so pretty printing put the closing tag on a new line. This made toEqualHtml fail for a non-shadow component that only renders a <slot>, since the slot reference comment is removed but <cmp-a></cmp-a> was serialized as <cmp-a>\n</cmp-a>. fixes: stenciljs#3218
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the current behavior?
GitHub Issue Number: #3218
A non-shadow component that only renders
<slot>can't be matched withtoEqualHtml. The slot reference comment gets dropped from the output because spec pages setremoveHtmlComments, but the serializer still counts it as a child, so with pretty printing<cmp-a></cmp-a>comes out as<cmp-a>\n</cmp-a>and the match fails.What is the new behavior?
In
serializeNodeToHtml, when an element's children are only comments that will be removed (plus optional whitespace text), the element is treated as empty, the same way a single whitespace text child already is. I pulled the existing "is this comment removed" check into a smallisRemovedCommenthelper so the comment branch and the new check use the same rule (hydrate annotations are still kept). The same check is used for the newline after a serialized shadow root, so a shadow component whose light DOM only holds a removed comment still prints its closing tag on its own line like before.Nothing changes when
removeHtmlCommentsis off.Documentation
N/A
Does this introduce a breaking change?
Testing
src/mock-doc/test/serialize-node.spec.ts: only removed comments (pretty and not), removed comments with whitespace, content next to a removed comment, comments kept when not removed, and a shadow root whose light DOM only has a removed comment.newSpecPagetest insrc/runtime/test/scoped.spec.tsxwith the component from the issue, checkingexpect(page.root).toEqualHtml('<cmp-a></cmp-a>').The two "only removed comments ... pretty" cases and the spec page test fail without the fix. I also ran
npx jest src/mock-doc src/runtime src/testing src/hydrateafternpm run buildand everything passes.Other information
The issue also mentions
scoped: truecomponents, which go through the same path.