Skip to content

Compiler shouldn't allow mixed of named slots and default slots #4561

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

Closed
tanhauhau opened this issue Mar 15, 2020 · 3 comments
Closed

Compiler shouldn't allow mixed of named slots and default slots #4561

tanhauhau opened this issue Mar 15, 2020 · 3 comments

Comments

@tanhauhau
Copy link
Member

Is your feature request related to a problem? Please describe.
When using named slots and default slots together, it is a bit hard to figure out the boundaries and whitespaces of the default slot:

<Component>
    <span>some code for default slot here</span>
    <div slot="a"></div>
    <span>some code for default slot here 2</span>
    <div slot="b"></div>
    some code for default slot here 3
</Component>

// default slot should contain

<span>some code for default slot here</span>
<span>some code for default slot here 2</span>
some code for default slot here 3

although it works, but it is messy. and it is hard to determine whether there's default slot in the first place, for example:

<Component>
    <div slot="a"></div>

   <!-- some white space -->
    <div slot="b"></div>
</Component>

Describe the solution you'd like
With #4556, we should complain if there's a mix of named slots and default slots, and encourage the user to use <svelte:slot slot="default"> and write:

<Component>
    <div slot="a"></div>
    <div slot="b"></div>
    <svelte:slot slot="default">
        <span>some code for default slot here</span>
       <span>some code for default slot here 2</span>
        some code for default slot here 3
    </svelte:slot>
</Component>

so, as long as there's name slot, any whitespace within the <Component> will not be considered.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

How important is this feature to you?
simpler and cleaner implementation of the slot mechanism

Additional context
Add any other context or screenshots about the feature request here.

@tanhauhau tanhauhau added the slot label Mar 15, 2020
@shirotech
Copy link

That looks like a breaking change, maybe just do a warning when there is ambiguous whitespace?

@zyzbroker
Copy link

zyzbroker commented Dec 18, 2020

add should eliminate the warning message as shown below

@tanhauhau
Copy link
Member Author

In 3.35.0, <svelte:fragment /> is implemented.

You can do

<Component>
    <div slot="a">a</div>
    <div slot="b">b</div>
    <svelte:fragment slot="default">
        <span>some code for default slot here</span>
       <span>some code for default slot here 2</span>
        some code for default slot here 3
    </svelte:fragment>
</Component>

instead

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

No branches or pull requests

3 participants