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

Element placed in slot called "undefined" #946

Open
1 task
ferencalmasi opened this issue Sep 28, 2023 · 2 comments
Open
1 task

Element placed in slot called "undefined" #946

ferencalmasi opened this issue Sep 28, 2023 · 2 comments
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@ferencalmasi
Copy link

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?

  • The condition should be taken into consideration, and the element should be placed outside of the slot
  • If the value of the slot prop is falsy (undefined, null, etc) the element should not be placed in a slot

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-zfaobp?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 Sep 28, 2023
@natemoo-re natemoo-re added the - P3: minor bug An edge case that only affects very specific usage (priority) label Sep 28, 2023
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Sep 28, 2023
@natemoo-re
Copy link
Member

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

@MoustaphaDev
Copy link
Member

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

@MoustaphaDev MoustaphaDev reopened this Jan 22, 2024
@MoustaphaDev MoustaphaDev self-assigned this Jan 22, 2024
@MoustaphaDev MoustaphaDev transferred this issue from withastro/astro Jan 22, 2024
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 22, 2024
@MoustaphaDev MoustaphaDev removed the needs triage Issue needs to be triaged label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

3 participants