- Issue created by @kentr
- šŗšøUnited States kentr Durango, CO
I think it's actually replacing any found file in
CriticalCssProvider.php
with whatever comes after that file in the list, even if that is a value ofFALSE
due to a failedfile_get_contents()
.Breaking out of the loop when a file is found fixes it:
diff --git a/src/Asset/CriticalCssProvider.php b/src/Asset/CriticalCssProvider.php index 052b31a..92e40ab 100644 --- a/src/Asset/CriticalCssProvider.php +++ b/src/Asset/CriticalCssProvider.php @@ -195,7 +195,10 @@ public function getCriticalCss() { } else { $this->criticalCss = @file_get_contents($this->matchedFilePath); + if ($this->criticalCss) { $this->criticalCss = trim($this->criticalCss); + break; + } } }
- šŗšøUnited States kentr Durango, CO
It appears to also fail for local files when CSS preprocessing is enabled.
In that case, the call to
file_get_contents()
only occurs if the file is external. - šŗšøUnited States kentr Durango, CO
Disregard my last comment about preprocessing CSS.
It appears that the blank output I'm getting is because the only content of the test CSS files are comments, which are getting stripped by the optimizer.
- Merge request !11Issue #3485325: Add break to loop in getCriticalCss() ā (Merged) created by kentr
- šŗšøUnited States kentr Durango, CO
This MR makes the test
CriticalCssHeadTest
pass, and I verified manually.Also tested manually with external asset URLs for ⨠Add support for downloading critical CSS from an URL Active .
-
albertosilva ā
committed ad7a184f on 2.0.x authored by
kentr ā
Issue #3485325: Add break to loop in getCriticalCss()
-
albertosilva ā
committed ad7a184f on 2.0.x authored by
kentr ā
- šŖšøSpain albertosilva Basque Country
Thanks @kentr for the MR!
Merged and new version published.
- Status changed to Fixed
3 months ago 3:56pm 29 January 2025 - š®š³India lomasr
Hi Alberto Silva,
Could you please confirm whether this patch applies to Drupal 10.3.10 and later versions as well? According to the description, it has been tested on Drupal 11. Iād like to make sure before upgrading the module from 2.0.0 to 2.0.3.