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

Rendering of slot fallback content is unpredictable. (Depending on code formatting) #4092

Closed
svensigmond opened this issue Dec 11, 2019 · 2 comments · Fixed by #4500
Closed

Comments

@svensigmond
Copy link

svensigmond commented Dec 11, 2019

Let me preface this ticket by saying that I am not 100% confident that this is actually a bug, but the behaviour does feel unnatural and unexpected.

Describe the bug
When using slots with fallback content inside a component, the rendering of the fallback content is unpredictable, depending on the formatting of the code.

If the opening and closing tag of the component are not on the same line, an empty string appears to be sent to the component, which is interpreted as content, thus not showing the fallback content.

I feel that this does not match the described behaviour for slot fallback content in the API documentation (https://svelte.dev/docs#slot):

The content is exposed in the child component using the element, which can contain fallback content that is rendered if no children are provided.

To Reproduce
Please refer to the following code example: https://svelte.dev/repl/f10ecd42506b4603839be1fe1ad8f8d4?version=3.16.3

Both Box 3 and Box 4 are rendered in an empty state, without fallback content.

Expected behavior
I would expect Box 3 and Box 4 to show the same fallback content as Box 1 and Box 2.

Information about your Svelte project:

  • Svelte version 3.16.3

Severity
I guess this behaviour is mostly annoying, because it can be circumvented, as shown in the example REPL. I do however feel that this workaround defeats the purpose of having the option to specify fallback content.

Additional context
I discussed this issue with Conduitry on Discord and he sent me this ticket, which might be the reason for the current behaviour: #1007

When browsing the open issues, I came across the following suggestion, which might be a way to solve this issue: #3080

@svensigmond
Copy link
Author

@tanhauhau / @Conduitry I checked my example page in version 3.19.2 (https://svelte.dev/repl/f10ecd42506b4603839be1fe1ad8f8d4?version=3.19.2) and even though the example in Box 3 is now rendering the fallback message as expected, the example in Box 4 does not, even though it is not rendering any content.

Should this issue be re-opened?

@tanhauhau
Copy link
Member

tanhauhau commented Mar 9, 2020

ah. @svensigmond i created another ticket: #4529

I fixed the case due to code formatting where there's only whitespace in the template code.

svelte havnt' able to handle the case where it is empty due to runtime conditions

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.

2 participants