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

Undefined class attribute is not filtered out with scopedStyleStrategy: 'class' #1005

Open
1 task
delucis opened this issue May 14, 2024 · 1 comment
Open
1 task
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@delucis
Copy link
Member

delucis commented May 14, 2024

Astro Info

Astro                    v4.8.3
Node                     v18.18.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

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

n/a / All

Describe the Bug

If a component sets the class attribute to undefined, this is stringified and included in build output when using scopedStyleStrategy: 'class', unlike behaviour for other attributes where setting them to undefinded causes the attribute to be omitted in build output.

For example, a component that does this:

<div class={undefined}>

Will render something like the following:

<div class="undefined astro-HASH">

What's the expected result?

The build output should not include undefined in the class attribute.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-sgqbuf?file=src%2FTest.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 May 14, 2024
@bluwy
Copy link
Member

bluwy commented May 15, 2024

Looks like a bug with the compiler. It generates code like this:

return $$render`<div${$$addAttribute((undefined) + " astro-ojezl33t", "class")}></div>`;

We probably need to update

case astro.ExpressionAttribute:
// as an expression
attr.Val = fmt.Sprintf(`(%s) + " %s"`, attr.Val, scopedClass)
n.Attr[i] = attr
return
}
to generate (undefined ?? '') instead.

@bluwy bluwy transferred this issue from withastro/astro May 15, 2024
@bluwy bluwy added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels May 15, 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

2 participants