Skip to content

Commit c89b523

Browse files
authored
Enhance CSS handling in ThemingController
Added extraction of @import and @-rules from custom CSS.
1 parent 8a57953 commit c89b523

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

apps/theming/lib/Controller/ThemingController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,14 @@ public function getThemeStylesheet(string $themeId, bool $plain = false, bool $w
408408
// from the rest of the CSS.
409409
$customCssWithoutComments = preg_replace('!/\*.*?\*/!s', '', $customCss);
410410
$customCssWithoutComments = preg_replace('!//.*!', '', $customCssWithoutComments);
411+
412+
// Extract @import rules, because they MUST appear at the very top of the final CSS
413+
// If they remain inside the theme scope or behind normal rules, browsers will ignore them
411414
preg_match_all('/(@import[^;]+;)/', $customCssWithoutComments, $imports);
412415
$importsCss = implode('', $imports[0]);
413416
$customCssWithoutImports = preg_replace('/(@import[^;]+;)/', '', $customCssWithoutComments);
414417

418+
// Extract all remaining @-rules (e.g. @media), because they cannot be nested inside the theme scope
415419
preg_match_all('/(@[^{]+{(?:[^{}]*|(?R))*})/', $customCssWithoutImports, $atRules);
416420
$atRulesCss = implode('', $atRules[0]);
417421
$scopedCss = preg_replace('/(@[^{]+{(?:[^{}]*|(?R))*})/', '', $customCssWithoutImports);

0 commit comments

Comments
 (0)