Skip to content

Inject polyfills after @import and body-less @layer #17493

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

Merged
merged 5 commits into from
Apr 2, 2025

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Apr 1, 2025

This PR fixes an issue where polyfills were injected at the top, but they should be after @import and body-less @layer rules.

This is necessary in case you are using Google fonts like this for example:

@import url('https://fonts.google.com');
@import "tailwindcss";

While the @import url(…); sits above @import "tailwindcss"; in the final generated CSS we injected the polyfills at the very beginning.

This PR will inject the polyfills after the first AST Node that is not:

  1. A comment
  2. An external import — @import url(…)
  3. A body-less layer — @layer foo, bar, baz;

The snapshots look a little confusing, but that's because Lightning CSS is optimizing the output and moving things around a bit:

image

Lightning CSS Playground

Fixes: #17494

@RobinMalfait RobinMalfait requested a review from a team as a code owner April 1, 2025 21:02
@RobinMalfait RobinMalfait force-pushed the fix/ensure-polyfills-after-imports-2 branch from 9a93293 to e50e91b Compare April 1, 2025 21:03
@RobinMalfait RobinMalfait marked this pull request as draft April 1, 2025 21:19
@RobinMalfait RobinMalfait force-pushed the fix/ensure-polyfills-after-imports-2 branch from e50e91b to 66090e8 Compare April 1, 2025 21:28
These snapshots look a bit confusing, but Lightning CSS is optimizing
the body-less `@layer` and moving things around a bit.
@RobinMalfait RobinMalfait marked this pull request as ready for review April 1, 2025 21:48
@RobinMalfait RobinMalfait enabled auto-merge (squash) April 1, 2025 21:50
@RobinMalfait RobinMalfait merged commit 3c937ec into main Apr 2, 2025
7 checks passed
@RobinMalfait RobinMalfait deleted the fix/ensure-polyfills-after-imports-2 branch April 2, 2025 09:05
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.

v4.1.0 CLI does not put @import at the beginning
2 participants