Skip to content

Commit

Permalink
Revert "[StimulusBundle] Introduce "use_optimized_attributes_renderin…
Browse files Browse the repository at this point in the history
…g" configuration"

This reverts commit 4af2a0e.
  • Loading branch information
Kocal committed Sep 24, 2024
1 parent 05ea4c3 commit 27a8660
Show file tree
Hide file tree
Showing 23 changed files with 138 additions and 390 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/ux.symfony.com.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,10 @@ jobs:
with:
php-version: '8.3'
tools: php-cs-fixer
- name: Install root dependencies
uses: ramsey/composer-install@v3
with:
working-directory: ${{ github.workspace }}
- name: Build root packages
run: php .github/build-packages.php
working-directory: ${{ github.workspace }}
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
working-directory: ux.symfony.com
dependency-versions: 'highest'
- name: php-cs-fixer
run: php-cs-fixer check --diff

Expand All @@ -54,18 +46,10 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- name: Install root dependencies
uses: ramsey/composer-install@v3
with:
working-directory: ${{ github.workspace }}
- name: Build root packages
run: php .github/build-packages.php
working-directory: ${{ github.workspace }}
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
working-directory: ux.symfony.com
dependency-versions: 'highest'
- name: twig-cs-fixer
run: vendor/bin/twig-cs-fixer lint templates --report=github

Expand Down
3 changes: 0 additions & 3 deletions src/Chartjs/tests/Kernel/TwigAppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$loader->load(function (ContainerBuilder $container) {
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
$container->loadFromExtension('twig', ['default_path' => __DIR__.'/templates', 'strict_variables' => true, 'exception_controller' => null]);
$container->loadFromExtension('stimulus', [
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
]);

$container->setAlias('test.chartjs.builder', 'chartjs.builder')->setPublic(true);
$container->setAlias('test.chartjs.twig_extension', 'chartjs.twig_extension')->setPublic(true);
Expand Down
4 changes: 0 additions & 4 deletions src/LiveComponent/tests/Fixtures/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ protected function configureContainer(ContainerConfigurator $c): void
'default_path' => '%kernel.project_dir%/tests/Fixtures/templates',
]);

$c->extension('stimulus', [
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
]);

$security = [
'password_hashers' => [InMemoryUser::class => 'plaintext'],
'providers' => ['users' => ['memory' => ['users' => ['kevin' => ['password' => 'pass', 'roles' => ['ROLE_USER']]]]]],
Expand Down
3 changes: 0 additions & 3 deletions src/Map/tests/Kernel/FrameworkAppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$loader->load(function (ContainerBuilder $container) {
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
$container->loadFromExtension('ux_map', []);
$container->loadFromExtension('stimulus', [
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
]);

$container->setAlias('test.ux_map.renderers', 'ux_map.renderers')->setPublic(true);
});
Expand Down
3 changes: 0 additions & 3 deletions src/Map/tests/Kernel/TwigAppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$loader->load(function (ContainerBuilder $container) {
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
$container->loadFromExtension('twig', ['default_path' => __DIR__.'/templates', 'strict_variables' => true, 'exception_controller' => null]);
$container->loadFromExtension('stimulus', [
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
]);
$container->loadFromExtension('ux_map', []);

$container->setAlias('test.ux_map.renderers', 'ux_map.renderers')->setPublic(true);
Expand Down
3 changes: 0 additions & 3 deletions src/Map/tests/Kernel/TwigComponentKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
'defaults' => [],
'anonymous_template_directory' => 'components',
]);
$container->loadFromExtension('stimulus', [
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
]);
$container->loadFromExtension('ux_map', []);

$container->setAlias('test.ux_map.renderers', 'ux_map.renderers')->setPublic(true);
Expand Down
3 changes: 0 additions & 3 deletions src/Notify/tests/Kernel/TwigAppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$loader->load(function (ContainerBuilder $container) {
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
$container->loadFromExtension('twig', ['default_path' => __DIR__.'/templates', 'strict_variables' => true, 'exception_controller' => null]);
$container->loadFromExtension('stimulus', [
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
]);
$container->loadFromExtension('mercure', [
'hubs' => [
'default' => [
Expand Down
3 changes: 0 additions & 3 deletions src/React/tests/Kernel/TwigAppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$loader->load(function (ContainerBuilder $container) {
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true, 'http_method_override' => false]);
$container->loadFromExtension('twig', ['default_path' => __DIR__.'/templates', 'strict_variables' => true, 'exception_controller' => null]);
$container->loadFromExtension('stimulus', [
'use_optimized_attributes_rendering' => false, // TODO: remove in the next major version
]);

$container->setAlias('test.twig', 'twig')->setPublic(true);
$container->setAlias('test.twig.extension.react', 'twig.extension.react')->setPublic(true);
Expand Down
7 changes: 0 additions & 7 deletions src/StimulusBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# CHANGELOG

## 2.20.0

- Add `$useOptimizedRendering` argument to `Symfony\UX\StimulusBundle\Dto\StimulusAttributes`, default to `false`
(to keep the current behavior).
In the next major version of StimulusBundle, this argument will be removed and the optimized rendering will be enabled by default.
- Add `use_optimized_attributes_rendering` configuration option to enable the optimized rendering of Stimulus attributes.

## 2.14.2

- Fix bug with finding UX Packages with non-standard project structure
Expand Down
1 change: 0 additions & 1 deletion src/StimulusBundle/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
->set('stimulus.helper', StimulusHelper::class)
->args([
service(Environment::class)->nullOnInvalid(),
abstract_arg('use optimized attribute rendering'),
])

->set('stimulus.twig_extension', StimulusTwigExtension::class)
Expand Down
6 changes: 0 additions & 6 deletions src/StimulusBundle/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,6 @@ directory and the ``controllers.json`` file if you need to use different paths:
- '%kernel.project_dir%/assets/controllers'
controllers_json: '%kernel.project_dir%/assets/controllers.json'
# It is recommended to configure the option to "true" to use a more-optimized
# rendering system in StimulusAttributes, but it may break your tests since
# it changes the HTML output.
# Note: this option will be removed in 3.0 and interpreted as "true"
use_optimized_attributes_rendering: false
.. _manual-installation:

Manual Installation Details
Expand Down
10 changes: 0 additions & 10 deletions src/StimulusBundle/src/DependencyInjection/StimulusExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ public function load(array $configs, ContainerBuilder $container): void
->replaceArgument(2, $config['controller_paths'])
->replaceArgument(3, $config['controllers_json']);

if (null === $config['use_optimized_attributes_rendering']) {
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__);
}
$container->findDefinition('stimulus.helper')
->replaceArgument(1, $config['use_optimized_attributes_rendering'] ?? false);

if (!class_exists(ImportMapConfigReader::class)) {
$container->removeDefinition('stimulus.asset_mapper.auto_import_locator');
}
Expand Down Expand Up @@ -83,10 +77,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('controllers_json')
->defaultValue('%kernel.project_dir%/assets/controllers.json')
->end()
->booleanNode('use_optimized_attributes_rendering')
->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.')
->defaultNull()
->end()
->end();

return $treeBuilder;
Expand Down
41 changes: 9 additions & 32 deletions src/StimulusBundle/src/Dto/StimulusAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class StimulusAttributes implements \Stringable, \IteratorAggregate
private array $actions = [];
private array $targets = [];

/**
* TODO: Remove the second argument and all related code in the next major version.
*/
public function __construct(private Environment $env, private bool $useOptimizedRendering = false)
public function __construct(private Environment $env)
{
}

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

if ($this->controllers) {
// TODO: Remove the condition and "else" block in the next major version
if ($this->useOptimizedRendering) {
$attributes[] = 'data-controller="'.$this->escape(implode(' ', $this->controllers), 'html').'"';
} else {
$attributes[] = 'data-controller="'.implode(' ', array_map(fn (string $controller) => $this->escape($controller, 'html_attr'), $this->controllers)).'"';
}
$attributes[] = 'data-controller="'.implode(' ', array_map(fn (string $controller) => $this->escape($controller, 'html_attr'), $this->controllers)).'"';
}

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

// TODO: Remove the condition and "else" block in the next major version
if ($this->useOptimizedRendering) {
$action = $this->escape($controllerName.'#'.$actionName, 'html');
if (null !== $eventName) {
$action = $this->escape($eventName, 'html').'->'.$action;
}
} else {
$action = $this->escape($controllerName, 'html_attr').'#'.$this->escape($actionName, 'html_attr');
if (null !== $eventName) {
$action = $this->escape($eventName, 'html_attr').'->'.$action;
}
$action = $this->escape($controllerName, 'html_attr').'#'.$this->escape($actionName, 'html_attr');
if (null !== $eventName) {
$action = $this->escape($eventName, 'html_attr').'->'.$action;
}

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

if ($this->targets) {
// TODO: Remove the condition and "else" block in the next major version
if ($this->useOptimizedRendering) {
$attributes[] = implode(' ', array_map(function (string $key, string $value): string {
return $key.'="'.$this->escape($value, 'html').'"';
}, array_keys($this->targets), $this->targets));
} else {
$attributes[] = implode(' ', array_map(function (string $key, string $value): string {
return $key.'="'.implode(' ', array_map(fn (string $target) => $this->escape($target, 'html_attr'), explode(' ', $value))).'"';
}, array_keys($this->targets), $this->targets));
}
$attributes[] = implode(' ', array_map(function (string $key, string $value): string {
return $key.'="'.implode(' ', array_map(fn (string $target) => $this->escape($target, 'html_attr'), explode(' ', $value))).'"';
}, array_keys($this->targets), $this->targets));
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/StimulusBundle/src/Helper/StimulusHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ final class StimulusHelper
{
private Environment $twig;

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

public function createStimulusAttributes(): StimulusAttributes
{
return new StimulusAttributes($this->twig, $this->useOptimizedAttributesRendering);
return new StimulusAttributes($this->twig);
}
}
Loading

0 comments on commit 27a8660

Please # to comment.