Astro throws “Invalid slot name” when you pass content to a named slot whose name is already a property of Astro.slots, most often has or render. Those names belong to the Astro.slots.has() and Astro.slots.render() methods, so Astro can’t also use them as slot names. Rename the slot, for example from render to preview, in both the component and every place that fills it.
Key Takeaways
- Reserved:
has,render, and built-in object property names such asconstructorortoString.- The error fires when content is passed to that slot, not when you declare
<slot name="...">.- Rename in two places: the
<slot name>in the component andslot="..."where it’s used.- Prefer descriptive names like
header,actions,media.
The exact error
Invalid slot name.
Unable to create a slot named `render`. `render` is a reserved slot name. Please update the name of this slot.
What causes it
When a component receives slotted content, Astro builds the Astro.slots object and adds one property per slot name so you can check it. Before adding each property, it checks whether the name is already defined on the object. has and render are methods of that object, and every JavaScript object also inherits names like constructor, toString and valueOf. Any of these collides:
---
// src/components/Card.astro (broken)
---
<div class="card">
<slot />
<slot name="render" />
</div>
---
// src/pages/index.astro
import Card from '../components/Card.astro';
---
<Card>
<p>Body</p>
<img slot="render" src="/preview.png" alt="Preview" />
</Card>
The fix
Pick a name that isn’t reserved and update both sides:
---
// src/components/Card.astro
const hasPreview = Astro.slots.has('preview');
---
<div class="card">
<slot />
{hasPreview && (
<figure class="card-preview">
<slot name="preview" />
</figure>
)}
</div>
---
// src/pages/index.astro
import Card from '../components/Card.astro';
---
<Card>
<p>Body</p>
<img slot="preview" src="/preview.png" alt="Preview" />
</Card>
Search the project for the old name so you don’t miss a usage:
# terminal
grep -rn 'slot="render"' src/
Choosing safe slot names
The check runs against the Astro.slots object, so anything that object already answers to is off limits. A quick rule: if Astro.slots.yourName would mean something before you add the slot, don’t use it. Names that describe the region, like header, media, actions or footer, never collide and make the component easier to read.
Our folder structure docs show where layouts and components live in a theme, and every theme in the Komal catalog has a live preview to compare against. For more component patterns, see conditional rendering in Astro, and Fragment and set:html for filling a slot without a wrapper element. The named slots docs cover the full syntax.
FAQ
What slot names are reserved in Astro?
has and render, which are methods of Astro.slots, plus names every JavaScript object already has, such as constructor, toString and valueOf.
How do I check if a slot has content in Astro?
Use Astro.slots.has('name'). It returns true when the parent passed content to that slot, so you can skip wrapper markup when it’s empty.
How do I fill a named slot without an extra element?
Use <Fragment slot="name">...</Fragment>. The content goes into the slot and the Fragment itself renders nothing.