Skip to content

Commit 21d69fc

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

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/TwigComponent/config/debug.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
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;
1920

2021
return static function (ContainerConfigurator $container) {
2122
$container->services()
@@ -27,6 +28,7 @@
2728
->args([
2829
service('ux.twig_component.component_logger_listener'),
2930
service('twig'),
31+
param('ux.twig_component.profiler_dump_components'),
3032
])
3133
->tag('data_collector', [
3234
'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)