Fix: Ensure @import rules are always inserted at the top of the stylesheet #1165
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses an issue in the
createGlobalCssFunction
where@import
rules might not always be inserted at the top of the stylesheet. According to the CSS specification, all@import
rules must appear before any other rules in a stylesheet. Failing to comply with this requirement results in the browser ignoring the@import
rules.Problem:
Previously, the
@import
rules were being inserted just before thethemed.group
marker using the following logic:This logic did not guarantee compliance with the CSS requirement for
@import
to always be at the top, as it depended on the position of thethemed.group
.Reference:
https://developer.mozilla.org/en-US/docs/Web/CSS/@import
Solution:
The
importIndex
is now explicitly set to0
, ensuring that all@import
rules are added to the top of the stylesheet:This guarantees that all
@import
rules comply with the CSS specification, regardless of other rules or markers in the stylesheet.Reason for Change:
CSS Specification:
@import
rules to be placed at the top of the stylesheet, before any other types of rules (e.g., style declarations, media queries, keyframes).@import
rules appear later in the stylesheet, they are ignored by the browser.Practical Implication:
@import
rules at the top ensures that external stylesheets are loaded and applied correctly, maintaining the intended style order and cascade.