Skip to content

Commit 27a8660

Browse files
committed
Revert "[StimulusBundle] Introduce "use_optimized_attributes_rendering" configuration"
This reverts commit 4af2a0e.
1 parent 05ea4c3 commit 27a8660

File tree

23 files changed

+138
-390
lines changed

23 files changed

+138
-390
lines changed

.github/workflows/ux.symfony.com.yaml

-16
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,10 @@ jobs:
2828
with:
2929
php-version: '8.3'
3030
tools: php-cs-fixer
31-
- name: Install root dependencies
32-
uses: ramsey/composer-install@v3
33-
with:
34-
working-directory: ${{ github.workspace }}
35-
- name: Build root packages
36-
run: php .github/build-packages.php
37-
working-directory: ${{ github.workspace }}
3831
- name: Install dependencies
3932
uses: ramsey/composer-install@v3
4033
with:
4134
working-directory: ux.symfony.com
42-
dependency-versions: 'highest'
4335
- name: php-cs-fixer
4436
run: php-cs-fixer check --diff
4537

@@ -54,18 +46,10 @@ jobs:
5446
- uses: shivammathur/setup-php@v2
5547
with:
5648
php-version: '8.3'
57-
- name: Install root dependencies
58-
uses: ramsey/composer-install@v3
59-
with:
60-
working-directory: ${{ github.workspace }}
61-
- name: Build root packages
62-
run: php .github/build-packages.php
63-
working-directory: ${{ github.workspace }}
6449
- name: Install dependencies
6550
uses: ramsey/composer-install@v3
6651
with:
6752
working-directory: ux.symfony.com
68-
dependency-versions: 'highest'
6953
- name: twig-cs-fixer
7054
run: vendor/bin/twig-cs-fixer lint templates --report=github
7155

src/Chartjs/tests/Kernel/TwigAppKernel.php

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3636
$loader->load(function (ContainerBuilder $container) {
3737
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
3838
$container->loadFromExtension('twig', ['default_path' => __DIR__.'/templates', 'strict_variables' => true, 'exception_controller' => null]);
39-
$container->loadFromExtension('stimulus', [
40-
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
41-
]);
4239

4340
$container->setAlias('test.chartjs.builder', 'chartjs.builder')->setPublic(true);
4441
$container->setAlias('test.chartjs.twig_extension', 'chartjs.twig_extension')->setPublic(true);

src/LiveComponent/tests/Fixtures/Kernel.php

-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ protected function configureContainer(ContainerConfigurator $c): void
121121
'default_path' => '%kernel.project_dir%/tests/Fixtures/templates',
122122
]);
123123

124-
$c->extension('stimulus', [
125-
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
126-
]);
127-
128124
$security = [
129125
'password_hashers' => [InMemoryUser::class => 'plaintext'],
130126
'providers' => ['users' => ['memory' => ['users' => ['kevin' => ['password' => 'pass', 'roles' => ['ROLE_USER']]]]]],

src/Map/tests/Kernel/FrameworkAppKernel.php

-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3737
$loader->load(function (ContainerBuilder $container) {
3838
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
3939
$container->loadFromExtension('ux_map', []);
40-
$container->loadFromExtension('stimulus', [
41-
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
42-
]);
4340

4441
$container->setAlias('test.ux_map.renderers', 'ux_map.renderers')->setPublic(true);
4542
});

src/Map/tests/Kernel/TwigAppKernel.php

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3838
$loader->load(function (ContainerBuilder $container) {
3939
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
4040
$container->loadFromExtension('twig', ['default_path' => __DIR__.'/templates', 'strict_variables' => true, 'exception_controller' => null]);
41-
$container->loadFromExtension('stimulus', [
42-
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
43-
]);
4441
$container->loadFromExtension('ux_map', []);
4542

4643
$container->setAlias('test.ux_map.renderers', 'ux_map.renderers')->setPublic(true);

src/Map/tests/Kernel/TwigComponentKernel.php

-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
5555
'defaults' => [],
5656
'anonymous_template_directory' => 'components',
5757
]);
58-
$container->loadFromExtension('stimulus', [
59-
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
60-
]);
6158
$container->loadFromExtension('ux_map', []);
6259

6360
$container->setAlias('test.ux_map.renderers', 'ux_map.renderers')->setPublic(true);

src/Notify/tests/Kernel/TwigAppKernel.php

-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
4141
$loader->load(function (ContainerBuilder $container) {
4242
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
4343
$container->loadFromExtension('twig', ['default_path' => __DIR__.'/templates', 'strict_variables' => true, 'exception_controller' => null]);
44-
$container->loadFromExtension('stimulus', [
45-
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
46-
]);
4744
$container->loadFromExtension('mercure', [
4845
'hubs' => [
4946
'default' => [

src/React/tests/Kernel/TwigAppKernel.php

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3636
$loader->load(function (ContainerBuilder $container) {
3737
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
3838
$container->loadFromExtension('twig', ['default_path' => __DIR__.'/templates', 'strict_variables' => true, 'exception_controller' => null]);
39-
$container->loadFromExtension('stimulus', [
40-
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
41-
]);
4239

4340
$container->setAlias('test.twig', 'twig')->setPublic(true);
4441
$container->setAlias('test.twig.extension.react', 'twig.extension.react')->setPublic(true);

src/StimulusBundle/CHANGELOG.md

-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
# CHANGELOG
22

3-
## 2.20.0
4-
5-
- Add `$useOptimizedRendering` argument to `Symfony\UX\StimulusBundle\Dto\StimulusAttributes`, default to `false`
6-
(to keep the current behavior).
7-
In the next major version of StimulusBundle, this argument will be removed and the optimized rendering will be enabled by default.
8-
- Add `use_optimized_attributes_rendering` configuration option to enable the optimized rendering of Stimulus attributes.
9-
103
## 2.14.2
114

125
- Fix bug with finding UX Packages with non-standard project structure

src/StimulusBundle/config/services.php

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
->set('stimulus.helper', StimulusHelper::class)
3030
->args([
3131
service(Environment::class)->nullOnInvalid(),
32-
abstract_arg('use optimized attribute rendering'),
3332
])
3433

3534
->set('stimulus.twig_extension', StimulusTwigExtension::class)

src/StimulusBundle/doc/index.rst

-6
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,6 @@ directory and the ``controllers.json`` file if you need to use different paths:
381381
- '%kernel.project_dir%/assets/controllers'
382382
controllers_json: '%kernel.project_dir%/assets/controllers.json'
383383
384-
# It is recommended to configure the option to "true" to use a more-optimized
385-
# rendering system in StimulusAttributes, but it may break your tests since
386-
# it changes the HTML output.
387-
# Note: this option will be removed in 3.0 and interpreted as "true"
388-
use_optimized_attributes_rendering: false
389-
390384
.. _manual-installation:
391385

392386
Manual Installation Details

src/StimulusBundle/src/DependencyInjection/StimulusExtension.php

-10
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ public function load(array $configs, ContainerBuilder $container): void
3838
->replaceArgument(2, $config['controller_paths'])
3939
->replaceArgument(3, $config['controllers_json']);
4040

41-
if (null === $config['use_optimized_attributes_rendering']) {
42-
trigger_deprecation('symfony/stimulus-bundle', '2.20', 'The configuration option "use_optimized_attributes_rendering" is deprecated. It is now interpreted as "false", but it will be interpreted as "true" (and removed) in the next major version. Configure "use_optimized_attributes_rendering" to "true" to use the new and optimized rendering system for Stimulus Attributes.', __METHOD__);
43-
}
44-
$container->findDefinition('stimulus.helper')
45-
->replaceArgument(1, $config['use_optimized_attributes_rendering'] ?? false);
46-
4741
if (!class_exists(ImportMapConfigReader::class)) {
4842
$container->removeDefinition('stimulus.asset_mapper.auto_import_locator');
4943
}
@@ -83,10 +77,6 @@ public function getConfigTreeBuilder(): TreeBuilder
8377
->scalarNode('controllers_json')
8478
->defaultValue('%kernel.project_dir%/assets/controllers.json')
8579
->end()
86-
->booleanNode('use_optimized_attributes_rendering')
87-
->info('Whether to use optimized rendering of Stimulus attributes or not. This is a performance optimization but a breaking change because it changes the generated HTML.')
88-
->defaultNull()
89-
->end()
9080
->end();
9181

9282
return $treeBuilder;

src/StimulusBundle/src/Dto/StimulusAttributes.php

+9-32
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ class StimulusAttributes implements \Stringable, \IteratorAggregate
2828
private array $actions = [];
2929
private array $targets = [];
3030

31-
/**
32-
* TODO: Remove the second argument and all related code in the next major version.
33-
*/
34-
public function __construct(private Environment $env, private bool $useOptimizedRendering = false)
31+
public function __construct(private Environment $env)
3532
{
3633
}
3734

@@ -113,12 +110,7 @@ public function __toString(): string
113110
$attributes = [];
114111

115112
if ($this->controllers) {
116-
// TODO: Remove the condition and "else" block in the next major version
117-
if ($this->useOptimizedRendering) {
118-
$attributes[] = 'data-controller="'.$this->escape(implode(' ', $this->controllers), 'html').'"';
119-
} else {
120-
$attributes[] = 'data-controller="'.implode(' ', array_map(fn (string $controller) => $this->escape($controller, 'html_attr'), $this->controllers)).'"';
121-
}
113+
$attributes[] = 'data-controller="'.implode(' ', array_map(fn (string $controller) => $this->escape($controller, 'html_attr'), $this->controllers)).'"';
122114
}
123115

124116
if ($this->actions) {
@@ -128,17 +120,9 @@ public function __toString(): string
128120
$actionName = $actionData['actionName'];
129121
$eventName = $actionData['eventName'];
130122

131-
// TODO: Remove the condition and "else" block in the next major version
132-
if ($this->useOptimizedRendering) {
133-
$action = $this->escape($controllerName.'#'.$actionName, 'html');
134-
if (null !== $eventName) {
135-
$action = $this->escape($eventName, 'html').'->'.$action;
136-
}
137-
} else {
138-
$action = $this->escape($controllerName, 'html_attr').'#'.$this->escape($actionName, 'html_attr');
139-
if (null !== $eventName) {
140-
$action = $this->escape($eventName, 'html_attr').'->'.$action;
141-
}
123+
$action = $this->escape($controllerName, 'html_attr').'#'.$this->escape($actionName, 'html_attr');
124+
if (null !== $eventName) {
125+
$action = $this->escape($eventName, 'html_attr').'->'.$action;
142126
}
143127

144128
return $action;
@@ -148,21 +132,14 @@ public function __toString(): string
148132
}
149133

150134
if ($this->targets) {
151-
// TODO: Remove the condition and "else" block in the next major version
152-
if ($this->useOptimizedRendering) {
153-
$attributes[] = implode(' ', array_map(function (string $key, string $value): string {
154-
return $key.'="'.$this->escape($value, 'html').'"';
155-
}, array_keys($this->targets), $this->targets));
156-
} else {
157-
$attributes[] = implode(' ', array_map(function (string $key, string $value): string {
158-
return $key.'="'.implode(' ', array_map(fn (string $target) => $this->escape($target, 'html_attr'), explode(' ', $value))).'"';
159-
}, array_keys($this->targets), $this->targets));
160-
}
135+
$attributes[] = implode(' ', array_map(function (string $key, string $value): string {
136+
return $key.'="'.implode(' ', array_map(fn (string $target) => $this->escape($target, 'html_attr'), explode(' ', $value))).'"';
137+
}, array_keys($this->targets), $this->targets));
161138
}
162139

163140
if ($this->attributes) {
164141
$attributes[] = implode(' ', array_map(function (string $attribute, string $value): string {
165-
return $attribute.'="'.$this->escape($value, $this->useOptimizedRendering ? 'html' : 'html_attr').'"';
142+
return $attribute.'="'.$this->escape($value, 'html_attr').'"';
166143
}, array_keys($this->attributes), $this->attributes));
167144
}
168145

src/StimulusBundle/src/Helper/StimulusHelper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ final class StimulusHelper
2222
{
2323
private Environment $twig;
2424

25-
public function __construct(?Environment $twig, private bool $useOptimizedAttributesRendering = false)
25+
public function __construct(?Environment $twig)
2626
{
2727
// Twig needed just for its escaping mechanism
2828
$this->twig = $twig ?? new Environment(new ArrayLoader());
2929
}
3030

3131
public function createStimulusAttributes(): StimulusAttributes
3232
{
33-
return new StimulusAttributes($this->twig, $this->useOptimizedAttributesRendering);
33+
return new StimulusAttributes($this->twig);
3434
}
3535
}

0 commit comments

Comments
 (0)