Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Add a way to mark a `Twig\Markup` instance as safe for some escaping strategies only
* Make `Environment::getExtension()` return the runtime of an extension class registered with `AttributeExtension`
* Make `Environment::getRuntime()` fall back to the registered extension of the same class
* Speed up merging the class lists in `html_cva()` recipes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in all similar PRs we can drop these lines IMHO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We alreay have Speed up ... entries in the changelog, but on the other hand they produce conflicts every time after a merge... 😅


# 3.30.0 (2026-09-25)

Expand Down
13 changes: 6 additions & 7 deletions extra/html-extra/Cva.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,29 @@ public function __construct(

public function apply(array $recipes, ?string ...$additionalClasses): string
{
$classes = $this->base;
$classLists = [$this->base];

// Resolve recipes against variants
foreach ($recipes as $recipeName => $recipeValue) {
$recipeClasses = $this->variants[$recipeName][self::toVariantName($recipeValue)] ?? [];
$classes = [...$classes, ...(array) $recipeClasses];
$classLists[] = (array) $recipeClasses;
}

// Resolve compound variants
foreach ($this->compoundVariants as $compound) {
$compoundClasses = $this->resolveCompoundVariant($compound, $recipes) ?? [];
$classes = [...$classes, ...$compoundClasses];
$classLists[] = $this->resolveCompoundVariant($compound, $recipes) ?? [];
}

// Apply default variants if specific recipes aren't provided
foreach ($this->defaultVariants as $defaultVariantName => $defaultVariantValue) {
if (!isset($recipes[$defaultVariantName])) {
$variantClasses = $this->variants[$defaultVariantName][self::toVariantName($defaultVariantValue)] ?? [];
$classes = [...$classes, ...(array) $variantClasses];
$classLists[] = (array) $variantClasses;
}
}
$classes = [...$classes, ...array_values($additionalClasses)];
$classLists[] = array_values($additionalClasses);

$classes = implode(' ', array_filter($classes, 'is_string'));
$classes = implode(' ', array_filter(array_merge(...$classLists), 'is_string'));

if (isset(self::$classListCache[$classes])) {
return self::$classListCache[$classes];
Expand Down
Loading