Conversation
printElement prints printOpeningTagPrefix for elements whose content is preserved (pre-like elements such as textarea), but printOpeningTag already prints that prefix through printOpeningTagStart. When the element borrows the previous sibling's closing `>`, it is printed twice, so `<label>a</label><textarea></textarea>` became `<label>a</label>><textarea></textarea>`. Fixes Shopify#1288
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 are you adding in this PR?
Fixes #1288
Root cause: in
printElement, the branch for elements whose content is preserved (pre-like elements such as<textarea>) printsprintOpeningTagPrefix(node)and thenprintOpeningTag(...). ButprintOpeningTagalready prints that same prefix throughprintOpeningTagStart. When the textarea has no whitespace before it, it borrows the previous sibling's closing>, and that>ends up printed twice:was formatted as
which adds a visible
>to the page. The same happens after a void element, e.g.<img src="a"><textarea>hi</textarea>.Fix: remove the duplicated
printOpeningTagPrefixcall from that branch, so it matches the other branches ofprintElement. The prefix is still printed once byprintOpeningTagStart.Test: added a case to the
html-elementfixture covering both the</label>and the<img>case. It fails before the fix (the output has>>) and passes after it, with Prettier 2 and 3. The fullprettier-plugin-liquidsuite and the idempotence run pass on both versions.What's next? Any followup issues?
None.
What did you learn?
Pre-like elements go through their own branch in
printElement, and no existing fixture had one borrowing the previous sibling's>, so this path was never covered.Tophatting
Before:
<div><label for="x">Name</label>><textarea id="x" rows="4"></textarea></div>After:
<div><label for="x">Name</label><textarea id="x" rows="4"></textarea></div>Before you deploy
changeset