Skip to content

fix: prevent whitespaces merging across component boundaries #12449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-hats-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: prevent whitespaces merging across component boundaries
6 changes: 5 additions & 1 deletion packages/svelte/src/compiler/phases/3-transform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ export function clean_nodes(
))),
/** if a component or snippet starts with text, we need to add an anchor comment so that its text node doesn't get fused with its surroundings */
is_text_first:
(parent.type === 'Fragment' || parent.type === 'SnippetBlock') &&
(parent.type === 'Fragment' ||
parent.type === 'SnippetBlock' ||
parent.type === 'SvelteComponent' ||
parent.type === 'Component' ||
parent.type === 'SvelteSelf') &&
first &&
(first?.type === 'Text' || first?.type === 'ExpressionTag')
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
const { children } = $props();
</script>

<p>text before the render tag {@render children()}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '../../test';

export default test({
html: `<p>text before the render tag dont fuse this text with the one from the child</p>`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import Child from './Child.svelte';
let text = $state('dont fuse this text with the one from the child');
</script>

<Child>{text}</Child>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default function Function_prop_no_getter($$anchor) {
onmouseup,
onmouseenter: () => $.set(count, $.proxy(plusOne($.get(count)))),
children: ($$anchor, $$slotProps) => {
$.next();

var text = $.text();

$.template_effect(() => $.set_text(text, `clicks: ${$.get(count) ?? ""}`));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Function_prop_no_getter($$payload) {
onmouseup,
onmouseenter: () => count = plusOne(count),
children: ($$payload, $$slotProps) => {
$$payload.out += `clicks: ${$.escape(count)}`;
$$payload.out += `<!---->clicks: ${$.escape(count)}`;
},
$$slots: { default: true }
});
Expand Down
Loading