Skip to content

Commit 6da25e6

Browse files
committed
[TwigComponent][Perf] Add option to disable the dump of components
1 parent 15e2163 commit 6da25e6

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/TwigComponent/config/debug.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
use Symfony\UX\TwigComponent\EventListener\TwigComponentLoggerListener;
1717

1818
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
19+
use function Symfony\Component\DependencyInjection\Loader\Configurator\param; // AJOUTER CETTE LIGNE
1920

2021
return static function (ContainerConfigurator $container) {
22+
2123
$container->services()
2224

2325
->set('ux.twig_component.component_logger_listener', TwigComponentLoggerListener::class)
@@ -27,6 +29,7 @@
2729
->args([
2830
service('ux.twig_component.component_logger_listener'),
2931
service('twig'),
32+
param('ux.twig_component.profiler_dump_components'),
3033
])
3134
->tag('data_collector', [
3235
'template' => '@TwigComponent/Collector/twig_component.html.twig',

src/TwigComponent/src/DataCollector/TwigComponentDataCollector.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ final class TwigComponentDataCollector extends AbstractDataCollector implements
3535
public function __construct(
3636
private readonly TwigComponentLoggerListener $logger,
3737
private readonly Environment $twig,
38+
private readonly bool $dumpComponents = true,
3839
) {
3940
$this->hasStub = class_exists(ClassStub::class);
4041
}
@@ -130,12 +131,15 @@ private function collectDataFromLogger(): void
130131
'input_props' => $mountedComponent->getInputProps(),
131132
'attributes' => $mountedComponent->getAttributes()->all(),
132133
'template_index' => $event->getTemplateIndex(),
133-
'component' => $mountedComponent->getComponent(),
134134
'depth' => \count($ongoingRenders),
135135
'children' => [],
136136
'render_start' => $profile[0],
137137
];
138138

139+
if ($this->dumpComponents) {
140+
$renders[$renderId]['component'] = $mountedComponent->getComponent();
141+
}
142+
139143
if ($parentId = end($ongoingRenders)) {
140144
$renders[$parentId]['children'][] = $renderId;
141145
}

src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function load(array $configs, ContainerBuilder $container): void
6969
$defaults = [];
7070
}
7171
$container->setParameter('ux.twig_component.component_defaults', $defaults);
72+
$container->setParameter('ux.twig_component.profiler_dump_components', $config['profiler_dump_components']);
7273

7374
$container->register('ux.twig_component.component_template_finder', ComponentTemplateFinder::class)
7475
->setArguments([
@@ -219,6 +220,10 @@ public function getConfigTreeBuilder(): TreeBuilder
219220
->info('Enables the profiler for Twig Component (in debug mode)')
220221
->defaultValue('%kernel.debug%')
221222
->end()
223+
->booleanNode('profiler_dump_components')
224+
->info('Enables the dump components for Twig Component (in debug mode)')
225+
->defaultValue('%kernel.debug%')
226+
->end()
222227
->scalarNode('controllers_json')
223228
->setDeprecated('symfony/ux-twig-component', '2.18', 'The "twig_component.controllers_json" config option is deprecated, and will be removed in 3.0.')
224229
->defaultNull()

src/TwigComponent/templates/Collector/twig_component.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,12 @@
293293
<th scope="row">Attributes</th>
294294
<td colspan="4">{{ profiler_dump(render.attributes) }}</td>
295295
</tr>
296+
{% if render.component is defined %}
296297
<tr>
297298
<th scope="row">Component</th>
298299
<td colspan="4">{{ profiler_dump(render.component) }}</td>
299300
</tr>
301+
{% endif %}
300302
</tbody>
301303
</table>
302304
{% endfor %}

0 commit comments

Comments
 (0)