Skip to content

fix: print() multiline behaviour#17319

Merged
Rich-Harris merged 10 commits intomainfrom
fix/print-new-lines
Jan 29, 2026
Merged

fix: print() multiline behaviour#17319
Rich-Harris merged 10 commits intomainfrom
fix/print-new-lines

Conversation

@manuel3108
Copy link
Member

@manuel3108 manuel3108 commented Dec 6, 2025

This is a follow-up to #16188. This fixes the multiline behavior and dramatically simplifies the implementation.
Draft, because this requires sveltejs/esrap#101 to be published.

Previously:

<div>
  <p>but multiline blocks in Svelte...</p>
</div>
<div>
  <p>...don't. It looks very cramped</p>
</div>

Now

<div>
  <p>but multiline blocks in Svelte...</p>
</div>

<div>
  <p>...don't. It looks very cramped</p>
</div>

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link

changeset-bot bot commented Dec 6, 2025

🦋 Changeset detected

Latest commit: d0a179f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2025

Playground

pnpm add https://pkg.pr.new/svelte@17319

@manuel3108
Copy link
Member Author

Fiiinnnallly, here we go!

@manuel3108 manuel3108 marked this pull request as ready for review January 20, 2026 19:15
Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks so good!

@svelte-docs-bot
Copy link

@Rich-Harris Rich-Harris merged commit 82fde88 into main Jan 29, 2026
18 checks passed
@Rich-Harris Rich-Harris deleted the fix/print-new-lines branch January 29, 2026 02:54
@github-actions github-actions bot mentioned this pull request Jan 29, 2026
Rich-Harris pushed a commit that referenced this pull request Feb 13, 2026
Follow-up to #17319.

The `Fragment` visitor in `print()` only flushed sequences on
`RegularElement`, causing block-level elements (`Component`,
`SvelteHead`, `SvelteBoundary`, etc.) to be lumped into the same
sequence as adjacent nodes. This broke tools that programmatically
manipulate the AST (e.g.
[sveltejs/cli#915](sveltejs/cli#915)).

The fix flushes before and after all block-level element types, ensuring
they get their own sequence and proper line separation.

### Before

```svelte
<svelte:head><title>Page Title</title></svelte:head><div>no space</div>
<Component /><Component />
<Component><span>child</span></Component><div>after component</div>
<svelte:boundary><div>boundary content</div></svelte:boundary><div>after boundary</div>
<!--comment--><div>after comment</div>
<div>before comment</div>
<!--comment-->

{#each items as item}
	<div>{item}</div>
{/each}<div>after each</div>

{@render children()}<div>after render</div>
<div>before render</div>
{@render children()}
```

### After

```svelte
<svelte:head><title>Page Title</title></svelte:head>
<div>no space</div>
<Component />
<Component />
<Component><span>child</span></Component>
<div>after component</div>
<svelte:boundary><div>boundary content</div></svelte:boundary>
<div>after boundary</div>
<!--comment-->
<div>after comment</div>
<div>before comment</div>
<!--comment-->

{#each items as item}
	<div>{item}</div>
{/each}

<div>after each</div>
{@render children()}
<div>after render</div>
<div>before render</div>
{@render children()}
```
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.

2 participants