Skip to content
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

Issue with slots containing multiple items / conditions #950

Closed
1 task
spacedawwwg opened this issue Jan 23, 2024 · 6 comments · Fixed by #952
Closed
1 task

Issue with slots containing multiple items / conditions #950

spacedawwwg opened this issue Jan 23, 2024 · 6 comments · Fixed by #952
Assignees
Labels
- P4: important Violate documented behavior or significantly improves performance (priority)

Comments

@spacedawwwg
Copy link

Astro Info

Astro                    v4.2.3
Node                     v20.10.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  none
Integrations             astro-dynamic-import
                         adds-to-head
                         @astrojs/vue
                         astro-purgecss
                         astro-compress

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

No response

Describe the Bug

as of v4.2.2, slots are not longer working correctly. When a slot has a loops, only the last item is being rendered. From what I can tell, its seems to be something to do with wrapping a slot in a condition (see reproduction)

This does not work (only last item in items is rendered)

---
import Layout from '../layouts/Layout.astro';
import Test from '../components/Test.vue';

const items = [1,2,3,4,5];
const test = false;

---
<Layout title="Welcome to Astro.">
    Outside
    <Test>
        {test && (
            <p slot={test ? 'test' : undefined}>
                Test name slot
            </p>
        )}
        {items.map(item => (
            <p>Item {item}</p>
        ))}
    </Test>
</Layout>

This does work (all items rendered)

---
import Layout from '../layouts/Layout.astro';
import Test from '../components/Test.vue';

const items = [1,2,3,4,5];
const test = false;
---

<Layout title="Welcome to Astro.">
    Outside
    <Test>
      <p slot={test ? 'test' : undefined}>
        Test name slot
      </p>
      {items.map(item => (
        <p>Item {item}</p>
      ))}
    </Test>
</Layout>

What's the expected result?

all items to be rendered in correct slots

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-vzmcxd?file=src%2Fpages%2Findex.astro,src%2Flayouts%2FLayout.astro,src%2Fcomponents%2FTest.vue

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 23, 2024
@spacedawwwg spacedawwwg changed the title Issue with slots containing multiple items Issue with slots containing multiple items / conditions Jan 23, 2024
@florian-lefebvre
Copy link
Member

Probably a regression introduced in withastro/astro#9605? @MoustaphaDev what do you think? I don't know anything about slots or the compiler, I hope you don't mind the ping 😅

@spacedawwwg
Copy link
Author

spacedawwwg commented Jan 24, 2024

Previously, we had to use both:

{test && (
  <p slot={test ? 'test' : undefined}>
    Test name slot
  </p>
)}

as the named slot was always showing, no matter if test was defined. Not sure what changes were made to slots, but an example of "best practice" for the above would also be appreciated

@MoustaphaDev
Copy link
Member

MoustaphaDev commented Jan 24, 2024

Thanks for the ping @florian-lefebvre! Yeah that's probably a regression, I'll take a look today!

@MoustaphaDev MoustaphaDev self-assigned this Jan 24, 2024
@ematipico ematipico transferred this issue from withastro/astro Jan 24, 2024
@MoustaphaDev
Copy link
Member

MoustaphaDev commented Jan 24, 2024

As a temporary workaround, you can wrap the second expression in a fragment @spacedawwwg

---
import Layout from '../layouts/Layout.astro';
import Test from '../components/Test.vue';

const items = [1,2,3,4,5];
const test = false;

---
<Layout title="Welcome to Astro.">
    Outside
    <Test>
        {test && (
            <p slot={test ? 'test' : undefined}>
                Test name slot
            </p>
        )}
        <>
            {items.map(item => (
                <p>Item {item}</p>
            ))}
        </>
    </Test>
</Layout>

Sorry for the trouble! I'll try to push a fix as soon as possible!

@spacedawwwg
Copy link
Author

get in, @MoustaphaDev 🚀

@ZeldOcarina
Copy link

Kindly please reopen this. See #959.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants