-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Incorrect error message "... received an unexpected slot "default". #4546
Comments
it would be helpful if you provide us a simple repro that we can take a look? |
I am not sure, how I could make a simpler repro than the one from the tutorial I linked? |
tangentially related, but this is fixed in #4556, in this test case: https://github.com/sveltejs/svelte/pull/4556/files#diff-4fdcde5b851c691eb791748d997f0969L6 |
I have the same problem: received an unexpected slot "default". This is the code with the problem:
|
This also incorrectly produces an error. <svelte:component this={Component}>{#if hasChild}<Child />{/if}</svelte:component> |
@voscausa warnings are only shown in dev mode. |
Is the issue fixed? There is a warning in the console that says I have three components
In Button.svelte, I have an unnamed
Card component has two named
and both When I expand the warning, the If you want to check the source, feel free- https://github.com/venkateshwarans/starwars-svelte |
I was able to get rid of this warning by adding :
to my component - but that doesn't seem right... |
This should be better
|
I'm also getting this warning. Here's my code: {#if isLoading}
<slot name="loading">
<span>Your loading content here.</span>
</slot>
{:else if isMonetized}
<slot name="monetized">
<span>Monetized content here.</span>
</slot>
{:else}
<slot name="not-monetized">
<span>Your ads here.</span>
</slot>
{/if} |
Problem seems to be whitespace. I'm getting the error when there is whitespace between the named slots which I guess becomes the default slot that is unexpected. No warning:
Unexpected default slot:
|
Can confirm the above behaviour. The warning can only be removed by having no whitespace between named slots, which obviously isn't ideal. |
Came here to say I see this issue as well with/without whitespace and the only solution is to have a sibling default Just a minor inconvenience. |
Umm I've got this warning message too, but I decided to not bother addressing. This message is only shown during dev environment. So my question is should I even care to add a single line of code to remove this warning message? After all this is not an Error message. Since when you build for production this message is never shown on runtime. Also what could be impacted by not adding the default slot, when your code is strictly placings named slots to place where you wish? Just feels like life is often too short to address all the warning signs |
Yup, happening to me too. I'd remove the whitespace but then I have to remove my IDE's format on save special for just this file. Choosing to ignore for now, but it'd be nice for this to get address 👍 |
FYI adding an unnamed slot with I had an issue where adding an unnamed slot to a This really confused me when the content first appeared - getting rid of |
@chimp1nski, you can use the |
i ahve the same problem, the {#if false}{/if} hack got rid of it |
I have a Modal component with some slots and receiving the same warning. |
This should be fixed now in 3.35.0. |
I'm still getting the error when using this to generate recursive nested components: <script>
export let components;
</script>
<svelte:component this={components[0]}>
{#if components[1]}
<svelte:self slot="route-child" components={components.slice(1)}/>
{/if}
</svelte:component> The Here's a REPL that shows the error: https://svelte.dev/repl/f246cb87fc314e159fc9f20e81737ae5 In the REPL the recursion breaks for some reason but I can provide a repository with a working repro if that will help. Edit: So I removed the warning by just using the default slot, but still, a default slot shouldn't be needed when only passing content that should be mounted on a named slot, no? <script>
export let components;
</script>
{#if components.length > 1}
<svelte:component this={components[0]}>
<svelte:self components={components.slice(1)}/>
</svelte:component>
{:else}
<svelte:component this={components[0]}/>
{/if} |
I'm facing the same warning when using a child layout with SvelteKit. Minimum reproducible code: <!-- routes/$layout.svelte -->
<h1>Svelte</h1>
<nav>
<a href="/">Home</a>
<a href="/page1">Page 1</a>
<a href="/page2">Page 2</a>
</nav>
<slot />
<!-- routes/index.svelte -->
<p>Home</p>
<!-- routes/page1.svelte -->
<p>Page 1</p>
<!-- routes/page2/$layout -->
<p>Page 2</p>
<nav>
<a href="/page2">Main</a>
<a href="/page2/sub1">Subpage 1</a>
</nav>
<slot />
<!-- routes/page2/index.svelte -->
<p>Main</p>
<!-- routes/page2/sub1.svelte -->
<p>Subpage 1</p> Before having a child layout on |
Same warning here just using
|
Still got the same warning with Svelte Message
Template <div class="ts-divider">
<!-- Text -->
{#if $$slots.default}
<div class="ts-divider__text">
<div class="ts-divider__text__start">
<div class="ts-divider__text__line"></div>
</div>
<div class="ts-divider__text__center">
<slot></slot>
</div>
<div class="ts-divider__text__end">
<div class="ts-divider__text__line"></div>
</div>
</div>
{/if}
<!-- / Text -->
<!-- Line Only -->
{#if !$$slots.default}
<div class="ts-divider__line"></div>
{/if}
<!-- / Line Only -->
</div> |
Yes, same for me, at the init phase. |
Same for me, I don't even added a slot or have a sub-pages, just index.svelte:
Only the layout.svelte component has a |
Since the issue didn't get re-opened, I've created a new issue for this. [AGAIN] Incorrect error message "... received an unexpected slot "default". |
@tanhauhau Sadly, the bug isn't fixed. I think this needs to be reopened. Simple reproduction: |
Encountering this bug in Aug 2021 |
Same bug, 10 sep 2021 |
same bug, september 17th, 2021 |
Encountering this bug in Dec 2021 |
@tanhauhau any word on this? |
Also encountering this bug, with a fresh project which I setup this week (late December, 2021) |
Describe the bug
When passing 2 named slots to a component, you get an error message in the console, although everything is correct.
To Reproduce
The problem can be seen right in the tutorial under 'Named slots' after clicking 'show me' and opening the console.
https://svelte.dev/tutorial/named-slots
Expected behavior
There should be no error massage in the console.
Severity
Inconvenient. It was leading me on a wrong path, when trying to find a real bug.
The text was updated successfully, but these errors were encountered: