withastro / compiler

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

🐛 BUG: Ternary expressions in slot erase everything else #955

Closed tamaracha closed 9 months ago

tamaracha commented 9 months ago

What version of @astrojs/compiler are you using?

2.5.2

What package manager are you using?

npm

What operating system are you using?

Mac OS Ventura 13.6.1

Describe the Bug

If a slot, e.g., a layout's default slot, contains multiple elements and if one of them is a jsx ternary expression, only this one remains and the other ones disappear. It looks similar to #950, but with ternary instead of loops.

Everything before and after this within a slot will be erased:

{isLeaf ? <p>Leaf</p> : <p>Branch</p>}

Moving the expression into a fragment solves the problem:

<>
  {isLeaf ? <p>Leaf</p> : <p>Branch</p>}
</>

Is this intended?

My reprex is the astro blog template with the critical addition in the BlogPost layout.

Link to Minimal Reproducible Example

https://github.com/tamaracha/reprex-astro-syntax

MoustaphaDev commented 9 months ago

Thanks for reporting the issue! This seems like regression that snuck in with the last patch. I'll dig into this further to get a fix ASAP.

ferencalmasi commented 9 months ago

A similar issue is happening with fragments. It might be related to this. Link to issue: https://github.com/withastro/astro/issues/9997