alleyinteractive / alleyinteractive/wp-asset-manager
Critical CSS doesn't respect dependency order
- Dominant language
- PHP
- Stars
- 30
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
When more than one critical CSS file is registered (for example, one from a parent theme and one from a child theme) the dependencies are not respected. They get output in the order in which `add_asset()` is called, not according to their dependencies.
In the code below, `critical-first` should be output first because it's a dependency of `critical-second`, but `critical-second` gets output first because that's the order in which `add_asset()` is called.
```php
$styles = [
[
'condition' => 'global',
'deps' => [
'critical-first',
],
'handle' => 'critical-second',
'load_hook' => 'am_critical',
'load_method' => 'inline',
'src' => MY_PATH . '/critical-second.css',
'version' => 1,
],
[
'condition' => 'global',
'deps' => [],
'handle' => 'critical-first',
'load_hook' => 'am_critical',
'load_method' => 'inline',
'src' => MY_PATH . '/critical-first.css',
'version' => 1,
],
];
array_map( [ \Asset_Manager_Styles::instance(), 'add_asset' ], $styles );
```
Contributor guide
Assessment
This issue has not been assessed yet.