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

The combination of a global and a local selector should be a local selector #73

Closed
jantimon opened this issue Jul 17, 2024 · 1 comment · Fixed by #82
Closed

The combination of a global and a local selector should be a local selector #73

jantimon opened this issue Jul 17, 2024 · 1 comment · Fixed by #82

Comments

@jantimon
Copy link
Contributor

jantimon commented Jul 17, 2024

html { a_value: some-value; } is not local - and therefore css-modules/postcss-modules-local-by-default marks them as not pure.

However if only local selectors are inside that non local selector, it is still fine as all declarations are wrapped by a local selector.
The following examples are pure:

html { 
  .foo { 
     a_value: some-value; 
  } 
}
html { 
 .foo { a_value: some-value; } 
 .bar { a_value: some-value; }
}

As soon as a non local declaration gets added it still be marked as non pure.
The following examples are NOT pure:

html { 
 .foo { a_value: some-value; } 
 button { a_value: some-value; } 
}
html { 
  .foo { 
     a_value: some-value; 
  } 
  color: red;
}
html { 
 .foo { a_value: some-value; } 
 button { 
   color: red;
   .bar { a_value: some-value; }
  } 
}

Especially the second case will be tricky to implement in the current code as by now only the selectors are analyzed to find out wether the code is pure or not.

In future we would have to iterate over every declaration and check for its surrounding selector wether it is pure or not.

@jantimon
Copy link
Contributor Author

jantimon commented Aug 6, 2024

I created a small next.js demo project with the following css code:

.page {
  button {
    color: green;
  }
}

Stackblitz without postcss-nesting
without postcss-nesting .page { button { .. } } is not pure:

shot-MPwBLLsD@2x

however the same css code works once you add postcss-nesting

Stackblitz with postcss-nesting
shot-mTFxVBKN@2x

to align both cases I created #72 - and to proof that .page button I created a pr with a test case in #74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant