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

CssSyntax error: Selector "&:hover" is not pure (pure selectors must contain at least one local class or id) #33734

Closed
equinusocio opened this issue Jan 27, 2022 · 2 comments · Fixed by #62644
Labels
bug Issue was opened via the bug report template.

Comments

@equinusocio
Copy link

Run next info (available from version 12.0.8 and up)

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:29:10 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T8101
Binaries:
  Node: 14.18.3
  npm: 8.3.1
  Yarn: 1.22.11
  pnpm: N/A
Relevant packages:
  next: 12.0.8
  react: 17.0.2
  react-dom: 17.0.2

What version of Next.js are you using?

12.0.8

What version of Node.js are you using?

14.18.3

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

CssSyntax error: Selector "&:hover" is not pure (pure selectors must contain at least one local class or id) (4:3)

color: pink;

  &:hover {
    color: purple; 
}

The above repository is based on following the examples in the documentation:
https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css

This issue has been opened again since the original one has been closed for "no activities" while last comment was posted 3 months ago. The issue still exists.

Expected Behavior

As far as I understand, the above selector does contain a "pure selector", so it should work. However, apparently, since hover is nested in this example, it isn't recognized as a "pure selector".

To Reproduce

https://github.com/andrasna/hello-next-css-module-issue

@equinusocio equinusocio added the bug Issue was opened via the bug report template. label Jan 27, 2022
@balazsorban44
Copy link
Member

I could not reproduce this using the latest version of Next.js. It should work with any version above Next.js 9 (which I found in your reproduction). Please upgrade. 🙏

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2022
samcx added a commit that referenced this issue Feb 29, 2024
today ~83% of all browsers support css nesting:
https://caniuse.com/css-nesting

![CSS Nesting Browser
Support](https://github.com/css-modules/postcss-modules-local-by-default/assets/4113649/141f8dce-a8bd-4df4-b2bd-210252189711)
https://caniuse.com/css-nesting  
https://developer.mozilla.org/en-US/docs/Web/CSS/Nesting_selector

therefore this pr upgrades postcss-modules-local-by-default which fixes
a bug in
css-modules/postcss-modules-local-by-default#64)

-  `.foo { &:hover { a_value: some-value; } }` is pure
-  `.foo { html &:hover { a_value: some-value; } }` is pure
-  `.foo { &:global(.bar) { a_value: some-value; } }` is pure
-  `:global(.foo) { &:hover { a_value: some-value; } }` is **not** pure


upgrading the package will allow using css nestings with or **without**
postcss compilation

it fixes the following error:

```
CssSyntaxError: postcss-modules-local-by-default: <css input>:1:8: Selector "&:hover" is not pure (pure selectors must contain at least one local class or id)
```

Fixes #55053
Fixes #33734
Fixes #10475

Co-authored-by: Sam Ko <sam@vercel.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants