Only @import rules at top of aggregated stylesheets should be resolved.

E.g.

@import url(style1.css);
/* comment */
@import url(style2.css);

body {
  color: red;
}

@import url(style3.css);

In this case only style1.css and style2.css should be resolved.

Comments

casey’s picture

For more info see: http://www.w3.org/TR/REC-CSS2/cascade.html#at-import

This issue is not very urgent as long as modules have valid stylesheets without @import rules that aren't at the top.

casey’s picture

Note that currently also @import rules are resolved that occur in comments. e.g.

/* To enable this-and-that, uncomment the next line. */
/*@import url(this-and-that.css);*/

body {
  color: blue;
}

Result of CSS aggregation:

/* To enable this-and-that, uncomment the next line. */
/*
.this-and-that {
  color: red;
}
*/

body {
  color: blue;
}
casey’s picture

Version: 7.x-dev » 8.x-dev
wim leers’s picture

Now that #352951: Make JS & CSS Preprocessing Pluggable has landed, along with better tests for CSS aggregation/minification, it should be a whole lot easier to do this. See #2014851: Drupal CSS preprocessing breaks protocol-relative paths for an example.

dawehner’s picture

Component: base system » asset library system
Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

johnalbin’s picture

Status: Active » Postponed (maintainer needs more info)

The latest spec for CSS @import rules is the CSS Cascade Level 4. It says:

Any @import rules must precede all other valid at-rules and style rules in a style sheet (ignoring @charset), or else the @import rule is invalid.

Now the issue description says:

Only @import rules at top of aggregated stylesheets should be resolved.

But, of course, the CSS spec says nothing about whether Drupal should maintain valid URLs in invalid @import statements. Since we are moving files around, it makes sense for us to fix the URLs that we would otherwise be breaking, even if those statements are later ignored by browsers.

What is the actual expected behavior that is broken? I don't see any harm in resolving URLs in invalid @import statements. In fact, it would take more code to stop us from resolving these @import statements. Plus, if the aggregation process is pluggable, some contrib plugin could decide it wants to act on those invalid @import and it would be nice if core continued to ensure the URLs were valid inside the @import statement.

I'm tempted to close this with "won't fix" but I'll see if someone else has other thoughts.

darvanen’s picture

Version: 8.9.x-dev » 9.3.x-dev
Status: Postponed (maintainer needs more info) » Closed (duplicate)
Related issues: +#646246: Only move non-resolved @import rules to top of aggregate stylesheet when also at top in own stylesheet

I think the problem is that when combined with #646246: Only move non-resolved @import rules to top of aggregate stylesheet when also at top in own stylesheet this causes rules that would otherwise not be used by a browser come into play.

I agree that resolving URLs as we move files around in itself isn't a problem, I'm going to close this as a duplicate rather than "won't fix" to indicate it's part of the same issue.

darvanen’s picture

Issue tags: +Bug Smash Initiative