Performance: Slots for content projection
Slots affect how content is inserted and rendered inside components, impacting rendering speed and layout stability.
<MyComponent>
<div slot="header">Single stable header content</div>
</MyComponent><MyComponent> <div slot="header">Dynamic header content</div> <div slot="header">Another header content</div> </MyComponent>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple elements in one slot | Increased nodes | Multiple reflows | High paint cost | [X] Bad |
| Single element per slot | Minimal nodes | Single reflow | Low paint cost | [OK] Good |
| Complex fallback content | Extra style calculations | Extra reflows | Medium paint cost | [!] OK |
| Simple fallback content | Minimal style work | Single reflow | Low paint cost | [OK] Good |
slots in Astro components?header in an Astro component?<MyComponent> <h1 slot="title">Welcome</h1> <p>Enjoy your stay</p> </MyComponent>
MyComponent.astro you have:<slot name="title" /> <slot />
<MyComponent> <div slot="footer">Footer content</div> </MyComponent>
MyComponent.astro you have:<slot name="header" /> <slot />
Card component with slots for header, body, and footer. Which Astro component code correctly sets up these named slots?Pass the test and this pattern moves unknown