- Issue created by @kentr
- πΊπΈUnited States kentr
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
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
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
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.