Skip to content

Fix incorrect cascade layer order when some resources can not be inlined #574

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

Conversation

romainmenke
Copy link
Collaborator

@romainmenke romainmenke commented Jun 2, 2025

Fixes the original problem described in #567 (comment)

The root cause is that all nodes are added to either the imports or bundle array in

const imports = []
const bundle = []

While @layer statements (those without a rule body) can precede @import.
To fix this issue I've added a new statement type for layers and added the needed mechanics to apply conditions to these. To express conditional @layer statements before other @import statements, or @layer statements that end up in between other @import statements we use base64 encoded stylesheets:

@import 'data:text/css;base64,QGxheWVyIGxheWVyLWJldGE=' print; is equivalent to @media print { @layer layer-beta } but is valid before other @import statements

I am unsure if it fixes all other reported examples as I don't have reproductions for those. I suggest they test out the fix (if/when it lands) and file new issues if they still encounter problems.

I verified the fix by re-testing with https://github.com/romainmenke/css-import-tests
With the patch applied 4 more test cases pass, without regressions in other cases.

@romainmenke romainmenke force-pushed the fix-layer-statements-before-remote-resources--compassionate-binturong-29d29caaa7 branch from 07a99a0 to f5883c4 Compare June 2, 2025 14:24
@RyanZim RyanZim merged commit 83108aa into master Jun 7, 2025
2 checks passed
@RyanZim RyanZim deleted the fix-layer-statements-before-remote-resources--compassionate-binturong-29d29caaa7 branch June 7, 2025 18:47
@RyanZim
Copy link
Collaborator

RyanZim commented Jun 7, 2025

Will release next week

@RyanZim
Copy link
Collaborator

RyanZim commented Jun 9, 2025

Actually, there's no good reason for me to be the bottleneck for npm releases; @romainmenke I should add you on npm; just to confirm, you're https://www.npmjs.com/~romainmenke there?

@romainmenke
Copy link
Collaborator Author

Yes, that's me :)

@RyanZim
Copy link
Collaborator

RyanZim commented Jun 10, 2025

@romainmenke Invitation sent; feel free to push the version bump/CHANGELOG update directly to master.

@romainmenke
Copy link
Collaborator Author

Thank you @RyanZim, I've released a new version.
Please do let me know if you spot any mistakes 🙇

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 this pull request may close these issues.

2 participants