Make CSS/JS order with the same weight deterministic

Created on 23 November 2014, almost 11 years ago
Updated 22 August 2025, about 1 month ago

Problem/Motivation

ore in D7/D8 does the following when adding CSS stylesheets:

    // Always add a tiny value to the weight, to conserve the insertion order.
    $options['weight'] += count($css) / 1000;
// ...
    $css[$data] = $options;

while the documentation does state that earlier attached files will win in the order if nothing else ...

This even applies when using only #attached! (and in Drupal 8)

Consider:

foo.css

a.css
b.css
c.css
a.css

The algorithm will do:

foo.css: 0
a.css: 0.001
b.css: 0.002
c.css: 0.003
a.css: 0.003

=> ORDER

b.css:0.002
a.css:0.003
c.css:0.003

I don't assume someone relies on that order, but it still is a bug and violates the specification how this should work. Only because we have different aggregation groups, this does not break horribly.

Proposed resolution

- Check if the weight exists, re-use the old weight if so.

- Another possibility is to increase the weight always instead.

Remaining tasks

- Upload patch
- Discuss

User interface changes

- None

API changes

- CSS order is earliest file wins within a group with same weight

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

theme system

Created by

πŸ‡©πŸ‡ͺGermany Fabianx

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024