Repository navigation
Conversation
Svelte 5 removes whitespace at the start and end of an element's content, so a line break after `>` or before `</` can't change what renders. Tags keep hugging inside `pre` and `textarea` and with strict whitespace sensitivity.
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.
Closes #547.
Svelte 5 removes whitespace at the start and end of an element's content (migration guide). Since 4.0 the plugin supports only Svelte 5, so a line break after
>or before</can't change what renders. The plugin still hugs those tags to avoid adding that whitespace, which gives this for #547's example:With this change it prints:
Whitespace between siblings still renders, so
</strong><small>and</span>,stay together as before. Content inside<pre>and<textarea>keeps hugging, and so doeshtmlWhitespaceSensitivity: "strict".Two smaller changes make the output match what you'd write by hand. When the source has no whitespace at an edge, the separator is a
softline, so<b>Bold</b>stays as it is when it fits instead of becoming<b> Bold </b>. A tag without attributes no longer breaks before its>, so an overflowing line doesn't end in<spanwith the>alone on the next line.The README FAQ about hugging described the Svelte 4 behavior, so I rewrote it.
Testing
16 fixtures have new expected output. I compiled the old and the new version of each with
svelte/compiler, client and server, and got identical code for every one. Three of them don't compile as whole files (animate:outside a keyed{#each},<svelte:fragment slot>without a parent), so for those I compiled only the elements that changed.Two fixtures are new. One holds #547's example and text right after an element. The other covers
<pre>and<textarea>, and its output is the same as before this change.I also ran the plugin over a SvelteKit app with 828 formatted components. It changed only the 27 files that still had the hugged layout, and each of them compiles to the same code as before.