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

@import with layer() places media queries outside of the layer #495

Closed
mvsde opened this issue Jun 26, 2022 · 2 comments · Fixed by #496
Closed

@import with layer() places media queries outside of the layer #495

mvsde opened this issue Jun 26, 2022 · 2 comments · Fixed by #496

Comments

@mvsde
Copy link

mvsde commented Jun 26, 2022

I created a basic reproduction case here: https://github.com/mvsde/postcss-cascade-layers

What’s happening:

I @import another CSS file with layer(test). That other file includes a media query.

After running this through PostCSS with the postcss-import plugin I get the following output:

@layer test {

body {}
}

@media (min-width: 50rem) {
  body {}
}

@layer test {

p {}
}

Note how the layer test is closed before the media query and “re-opened” afterwards.

I think the expected output should be something like:

@layer test {

body {}

@media (min-width: 50rem) {
  body {}
}

p {}
}
@romainmenke
Copy link
Collaborator

@mvsde Thank you for reporting this!

@romainmenke
Copy link
Collaborator

romainmenke commented Jun 26, 2022

@RyanZim I think I can resolve this but not easily without refactoring a substantial part of the code base.

Currently this plugin is written very dense and leverages many javascript mechanics (like reduce) that make it much harder to change parts.

Is this something you are open to?

This refactor should also make it possible to add support for supports conditions (@import url("foo.css") supports(not (display: flex));)


I will also attempt to fix this without refactoring anything major, hopefully this works 🤞

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.

2 participants