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

Scoped CSS miscompilation on pseudo-elements with only pseudo-classes #794

Open
1 task done
adri326 opened this issue May 11, 2023 · 2 comments
Open
1 task done
Labels
- P4: important Violate documented behavior or significantly improves performance (priority)

Comments

@adri326
Copy link

adri326 commented May 11, 2023

What version of astro are you using?

2.4.4

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

yarn

What operating system are you using?

Arch Linux, 6.3.1

What browser are you using?

Firefox

Describe the Bug

When applying scoped CSS to pseudo-elements in CSS selectors that only contain pseudo-classes, Astro incorrectly appends the :where clause to the ::before or ::after pseudo-element, stopping it from working altogether:

<style>
/* Works as expected */
ul > li::after,
ul > .fox::after,
ul > *::after,
ul > li:not(:first-child)::after,
{
    content: "🦊";
}

/* Does NOT work as expected */
ul > ::after,
ul > :not(:first-child)::after {
    content: "🦊";
}
</style>

Expected:

The latter CSS block should compile to the following:

ul:where(.scope) > :where(.scope)::after,
ul:where(.scope) > :where(.scope):not(:first-child)::after {
    content: "🦊";
}

Actual:

Instead, it gets compiled to this:

ul:where(.scope) > ::after:where(.scope),
ul:where(.scope) > :not(:first-child)::after:where(.scope) {
    content: "🦊";
}

I'd be willing to submit a pull request for this issue, but I would need guidance as to which parts of the codebase would need to be changed.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-lyys7u?file=src/pages/index.astro

Participation

  • I am willing to submit a pull request for this issue.
@bluwy
Copy link
Member

bluwy commented May 11, 2023

This looks like a bug in the compiler, which handles adding the scopes. I'll transfer this issue there.

If you'd like to fix this, the scoping logic mostly happen in this file! https://github.com/withastro/compiler/blob/e104c1c52728cbccc8b0e06a6dfaf7c05bcf1250/lib/esbuild/css_printer/astro_features.go

@bluwy bluwy transferred this issue from withastro/astro May 11, 2023
@bluwy bluwy added the - P3: minor bug An edge case that only affects very specific usage (priority) label May 11, 2023
@natemoo-re natemoo-re added - P4: important Violate documented behavior or significantly improves performance (priority) and removed - P3: minor bug An edge case that only affects very specific usage (priority) labels Jun 27, 2023
@evenfrost
Copy link

Faced this today.

I have the following HTML structure:

<div class="section-join">
  <a class="join-button">Join Now</a>
</div>

I'm using PostCSS with the nesting plugin.

When I try to write pseudo element class declaration like this:

.section-join {
  & .join-button {
    &::after {
      /* */
    }
  }
}

It incorrectly compiles to

:is(.section-join .join-button)::after[data-astro-cid-j7pv25f6] { }

But when I write

.section-join {
  & .join-button::after {
    /* */
  }
}

It compiles to

.section-join[data-astro-cid-j7pv25f6] .join-button[data-astro-cid-j7pv25f6]::after { }

And styles are applied as expected.

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

No branches or pull requests

4 participants