Skip to content
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

If slot content consists only of &nbsp, it is not passed to component #8359

Closed
danieldiekmeier opened this issue Mar 7, 2023 · 0 comments · Fixed by #8464
Closed

If slot content consists only of &nbsp, it is not passed to component #8359

danieldiekmeier opened this issue Mar 7, 2023 · 0 comments · Fixed by #8464

Comments

@danieldiekmeier
Copy link

Describe the bug

I have a simple component like this:

<h3 class="text-xl font-bold">
  <slot />
</h3>

Sometimes I don't want to show any content, but still want it to take up space. To achieve that, I want to pass an &nbsp;:

<MyComponent>&nbsp;</MyComponent>

But I noticed that the actual output in the DOM does not contain any spaces at all:

<h3 class="text-xl font-bold"></h3>

I expected:

<h3 class="text-xl font-bold">&nbsp;</h3>

Reproduction

https://svelte.dev/repl/9ece32e45c564cd68693684349802da6?version=3.55.1

If you look at the compiled JS output (especially obvious when using SSR), you can see that the compiler already "optimized" the &nbsp; away, and does not even try to pass it to the component.

<MyComponent>
	&nbsp;
</MyComponent>

Which leads to this output:

${validate_component(MyComponent, "MyComponent").$$render($$result, {}, {}, {})}
//                                                                          ^ Note the missing default

As a workaround, I was able to add an additional <span>:

<MyComponent>
	<span>&nbsp;</span>
</MyComponent>

Which leads to this output, which is what I would expect:

${validate_component(MyComponent, "MyComponent").$$render($$result, {}, {}, {
	default: () => {
		return `<span> </span>`;
	}
})}

Logs

No response

System Info

Svelte 3.55.1, straight from the REPL

Severity

annoyance

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 a pull request may close this issue.

1 participant