Skip to content

Fix stray > before a textarea that directly follows an element - #1303

Open
kwy404 wants to merge 1 commit into
Shopify:mainfrom
kwy404:fix-textarea-borrowed-bracket
Open

kwy404 wants to merge 1 commit into
Shopify:mainfrom
kwy404:fix-textarea-borrowed-bracket

Conversation

@kwy404

@kwy404 kwy404 commented Sep 26, 2026

Copy link
Copy Markdown

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>) prints printOpeningTagPrefix(node) and then printOpeningTag(...). But printOpeningTag already prints that same prefix through printOpeningTagStart. When the textarea has no whitespace before it, it borrows the previous sibling's closing >, and that > ends up printed twice:

<label for="x">Name</label><textarea id="x" rows="4"></textarea>

was formatted as

<label for="x">Name</label>><textarea id="x" rows="4"></textarea>

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 printOpeningTagPrefix call from that branch, so it matches the other branches of printElement. The prefix is still printed once by printOpeningTagStart.

Test: added a case to the html-element fixture 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 full prettier-plugin-liquid suite 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

  • I included a patch bump changeset

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
@kwy404
kwy404 requested a review from a team as a code owner September 26, 2026 14:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inserts extra ">" if: <label>text</label><textarea></textarea>

1 participant