Affected core versions
locale_css_alter() documents it will add the RTL CSS file directly after the original CSS file. This is incorrect and causes several overriding issues as I expect that the RTL override comes directly after the normal CSS file. The current logics has very strange side effects on overriding and often requires double overriding.
Currently broken order in RTL:
Expected order of CSS files:
Background and Solution:
locale_css_alter() adds a tiny value of
0.01 to the CSS weight, but this is a larger weight than the next LTR file has.
drupal_add_css() adds a tiny value to the weight by counting
$options['weight'] += count($css) / 1000; what results in a smaller value than
0.01. By adding a value of
0.0001 we are always smaller than 1/1000 and it now doesn't matter how many CSS files are added or not, the weight of the RTL file will always higher than it's LTR file and always smaller than the next LTR file. This make sure it really works as documented in
// Replicate the same item, but with the RTL path and a little larger
// weight so that it appears directly after the original CSS file.
PASSED: [[SimpleTest]]: [MySQL] 40,224 pass(es). View
FAILED: [[SimpleTest]]: [MySQL] 40,509 pass(es), 3 fail(s), and 0 exception(s). View
PASSED: [[SimpleTest]]: [MySQL] 40,116 pass(es). View
FAILED: [[SimpleTest]]: [MySQL] 40,411 pass(es), 3 fail(s), and 0 exception(s). View