Bug #82636
closedconcatenation changes include order of CSS files, breaks CSS.
0%
Description
I have some cssInline, which is automatically externalized into a css file (via config.removeDefaultJS = external).
And I have some CSS files, included via default page.includeCSS.
In the source code, they show up like:
<link rel="stylesheet" type="text/css" href="/fileadmin/site/framework/css/bootstrap.min.css?1506943541" media="all">
<link rel="stylesheet" type="text/css" href="/fileadmin/site/framework/css/main.css?1506943541" media="all">
<link rel="stylesheet" type="text/css" href="/fileadmin/site/framework/css/additions.css?1506943541" media="all">
<link rel="stylesheet" type="text/css" href="/fileadmin/site/framework-nc/css/main.css?1506694395" media="all">
<link rel="stylesheet" type="text/css" href="https://somedomain.tld/css/main.css" media="all">
<link rel="stylesheet" type="text/css" href="/typo3temp/assets/css/436ba33024.css?1506927672" media="all">
You see the externalized one at the bottom.
The externalized one is automatically "excludeFromConcatenation", because that's how things are done in \TYPO3\CMS\Frontend\Page\PageGenerator::addCssToPageRenderer() when called from \TYPO3\CMS\Frontend\Page\PageGenerator::renderContentWithHeader():
self::addCssToPageRenderer($cssPageStyle, true, 'InlinePageCss');
Now when concatenating the other files, suddenly this external file (page.cssInline) which is used to override some CSS of the above files, appears at the TOP of the list. Why?
Because this does not work in \TYPO3\CMS\Core\Resource\ResourceCompressor::concatenateCssFiles():
// place the merged stylesheet on top of the stylesheets
$cssFiles = array_merge($cssFiles, [$targetFile => $concatenatedOptions]);
At this point, $cssFiles is this:
Array ( [typo3temp/assets/css/edc1a6c625.css] => Array ( [file] => typo3temp/assets/css/edc1a6c625.css [rel] => stylesheet [media] => all [title] => [compress] => [forceOnTop] => [allWrap] => [excludeFromConcatenation] => 1 [splitChar] => | ) )
And [$targetFile => $concatenatedOptions] is this:
Array ( [typo3temp/assets/compressed/merged-9e3a4540615f81c720077bca7cad010d.css] => Array ( [file] => typo3temp/assets/compressed/merged-9e3a4540615f81c720077bca7cad010d.css [rel] => stylesheet [media] => all [compress] => 1 [excludeFromConcatenation] => 1 [forceOnTop] => [allWrap] => ) )
after the $cssFiles = array_merge($cssFiles, [$targetFile => $concatenatedOptions]), you get this:
Array ( [typo3temp/assets/css/edc1a6c625.css] => Array ( [file] => typo3temp/assets/css/edc1a6c625.css [rel] => stylesheet [media] => all [title] => [compress] => [forceOnTop] => [allWrap] => [excludeFromConcatenation] => 1 [splitChar] => | ) [typo3temp/assets/compressed/merged-9e3a4540615f81c720077bca7cad010d.css] => Array ( [file] => typo3temp/assets/compressed/merged-9e3a4540615f81c720077bca7cad010d.css [rel] => stylesheet [media] => all [compress] => 1 [excludeFromConcatenation] => 1 [forceOnTop] => [allWrap] => ) )
So, now the concatenated file is below the page.cssInline file - the previous include order is not preserved.
Therefore, array_merge() is not the right method here - or the array_merge() parameters need to be exchanged.
The comment line above the array_merge() even says:
// place the merged stylesheet on top of the stylesheets
But that's not happening - it is placed below the stylesheets, not no top.
Could it be that this is a regression?