withastro / compiler

The Astro compiler. Written in Go. Distributed as WASM.
Other
502 stars 59 forks source link

Element placed in slot called "undefined" #946

Open ferencalmasi opened 1 year ago

ferencalmasi commented 1 year ago

Astro Info

Astro                    v3.1.4
Node                     v18.18.0
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             @astrojs/mdx
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Rendering elements inside a ternary with a slot renders the element in the slot, regardless of the condition:

// The second div will be rendered inside the "slotted" slot.
{false
  ? <div slot="slotted">Inside slot with red background</div>
  : <div>Outside slot without background</div>
}

When setting a slot to undefined, it also creates a slot in Astro called "undefined":

<div slot={false ? 'named-slot' : undefined}>
  Added to slot named "undefined"
</div>

Logging Astro.slots˛ to the console gives us the following:

Slots { slotted: [Getter], undefined: [Getter] }

What's the expected result?

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-zfaobp?file=src%2Fpages%2Findex.astro

Participation

natemoo-re commented 1 year ago

I’m thinking this is a case we forgot to account for in the compiler! Would be great to fix.

MoustaphaDev commented 10 months ago

The "undefined" slot issue is still present, so I'll reopen this