use_css_critical_pathstyles-m.css, styles-l.css and print.css styles show up multiple times in developer tools.I have traced the problem to the following method:
beforeSendResponse in module-theme/Controller/Result/AsyncCssPlugin.php
This line appears to be re-inserting the original style tags:
$content = str_replace('</body', implode("\n", $cssMatches) . "\n</body", $content);
If you comment out this line, the HTML is as expected, with each style element existing only once and preventing double download of stylesheets.
I think there's some confusion over the implementation of the following technique:
<link rel="preload" as="style" media="all" onload="this.onload=null;this.rel='stylesheet'"href="...en_US/css/styles-m.css">
I would expect that the purpose of the onload method is that rather than needing one <link> to preload and a separate <link> at the bottom of the HTML to then achieve the affect of asynchronously loading the CSS, this behaviour can be achieved with just one <link> element. After onload event has fired, the rel attribute swaps and applies the CSS.
Hi @brightonmike. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.4-develop instance - upcoming 2.4.x release
For more details, please, review the Magento Contributor Assistant documentation.
@brightonmike do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?
@magento give me 2.4-develop instance
Hi @brightonmike. Thank you for your request. I'm working on Magento 2.4-develop instance for you
Hi @brightonmike, here is your Magento instance.
Admin access: https://i-26498-2-4-develop.instances.magento-community.engineering/admin_95bd
Login: b4063ce2 Password: 32017648ea26
Instance will be terminated in up to 3 hours.

Please see screenshot. As you will see the styles are showing up twice per style sheet.
For myself personally, this is causing problems debugging FE code. It looks like this issue is to force the specificity of the stylesheets over the critical inlined CSS.
Couple of possible work arounds:
onload event. The first style tags are simply for preload.Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
[ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop branchDetails
- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Add label Issue: Confirmed once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
:white_check_mark: Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-30771 were created
Issue Available: @engcom-Charlie, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._
I have encountered the same problem with magento 2.3.5. Has anyone managed to solve it?
@donatopirolo there's already a working merge request linked to this issue
Hi @brightonmike. Thank you for your report.
The issue has been fixed in magento/magento2#28480 by @mrtuvn in 2.4-develop branch
Related commit(s):
The fix will be available with the upcoming 2.4.1 release.
JsFooterPlugin the sort order of AsyncCssPlugin need to be negative. Else, the changes made by the plugin are not included in the cached result, when using FPC. So when the cache is not hit, CSS is processed correctly, however, if the cache is hit, the plugin is neither called nor are the changes already included in the cached response. The FPC uses a plugin on the same type (e.g. Magento\PageCache\Model\Controller\Result\BuiltinPlugin on Magento\Framework\Controller\ResultInterface which is a base of Magento\Framework\View\Result\Layout). So the AsyncCssPlugin needs to be called before the caching plugin. @mrtuvn Should I create a separate ticket for this?Yes this update only available in 2.4-develop and maybe available in next version
I will create new pr update for this order priority
Thanks @HenKun for discover this edge
Most helpful comment
Please see screenshot. As you will see the styles are showing up twice per style sheet.
For myself personally, this is causing problems debugging FE code. It looks like this issue is to force the specificity of the stylesheets over the critical inlined CSS.
Couple of possible work arounds:
onloadevent. The first style tags are simply for preload.