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

Conditionally rendered content overrides other content in slot #9990

Closed
1 task
MGSE97 opened this issue Feb 5, 2024 · 1 comment
Closed
1 task

Conditionally rendered content overrides other content in slot #9990

MGSE97 opened this issue Feb 5, 2024 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@MGSE97
Copy link

MGSE97 commented Feb 5, 2024

Astro Info

Astro                    v4.3.2
Node                     v19.8.1
System                   Windows (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

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

Chrome, Firefox, Opera

Describe the Bug

Hello,
I've been going through Build a blog tutorial, and I've noticed some content disappeared, when I wrapped it in layout.

When using ternary operator ?:, or && and || operators to render content in slot, only last resolved conditional content remains. Any other content passed into slot is removed.

Example:

<!-- wrapper.astro -->
<section>
  <slot />
</section>
---
const showContent = true;
---
<Wrapper>
  <p> Before content </p>
  {showContent ? <p> Some shown content </p> : <p> Some hidden content </p>}
  <p> After content </p>
</Wrapper>

Becomes:

<section>
  <p> Some shown content </p>
</section>

Instead of:

<section>
  <p> Before content </p>
  <p> Some shown content </p>
  <p> After content </p>
</section>

Without using <slot />, content renders as expected.
Workaround is to wrap condition in some other element (e.g. div).

<Wrapper>
  <p> Before content </p>
  <div>
     {showContent ? <p> Some shown content </p> : <p> Some hidden content </p>}
  </div>
  <p> After content </p>
</Wrapper>

What's the expected result?

  • Other content should not be removed/overwritten.
  • Conditional rendering should work same way with and without using slot.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/astro-yfzk5c-slot-issues?file=src%2Fpages%2Findex.astro

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 Feb 5, 2024
@MoustaphaDev
Copy link
Member

MoustaphaDev commented Feb 5, 2024

Thanks for taking the time to report the issue!
We're aware of the regression and we're working on a fix, so I'm going to close this in favor of withastro/compiler#955

@MoustaphaDev MoustaphaDev closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants