Skip to content

Commit 50fadb2

Browse files
committed
Fix component class collect
1 parent c7be9e0 commit 50fadb2

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/TwigComponent/src/DataCollector/TwigComponentDataCollector.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\VarDumper\Caster\ClassStub;
1919
use Symfony\Component\VarDumper\Cloner\Data;
2020
use Symfony\UX\TwigComponent\Event\PostRenderEvent;
21-
use Symfony\UX\TwigComponent\Event\PreCreateForRenderEvent;
2221
use Symfony\UX\TwigComponent\Event\PreRenderEvent;
2322
use Symfony\UX\TwigComponent\EventListener\TwigComponentLoggerListener;
2423
use Twig\Environment;
@@ -101,20 +100,16 @@ private function collectDataFromLogger(): void
101100
$ongoingRenders = [];
102101

103102
foreach ($this->logger->getEvents() as [$event, $profile]) {
104-
if ($event instanceof PreCreateForRenderEvent) {
105-
$componentName = $event->getName();
106-
// $components[$componentName]
107-
}
108-
109103
if ($event instanceof PreRenderEvent) {
110104
$mountedComponent = $event->getMountedComponent();
111105

112106
$metadata = $event->getMetadata();
113107
$componentName = $metadata->getName();
108+
$componentClass = $mountedComponent->getComponent()::class;
114109

115110
$components[$componentName] ??= [
116111
'name' => $componentName,
117-
'class' => $componentClass = $mountedComponent->getComponent()::class,
112+
'class' => $componentClass,
118113
'class_stub' => $this->hasStub ? new ClassStub($componentClass) : $componentClass,
119114
'template' => $metadata->getTemplate(),
120115
'template_path' => $this->resolveTemplatePath($metadata->getTemplate()), // defer ? lazy ?

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
margin-bottom: 2rem;
5454
}
5555
.twig-component-render {
56-
/*box-shadow: 0 0 0 1px var(--table-border-color);*/
5756
margin-left: calc(var(--render-depth) * .5rem);
5857
width: calc(100% - calc(var(--render-depth) * .5rem));
5958
}
@@ -83,15 +82,12 @@
8382
opacity: .85;
8483
transition: all 250ms ease-in-out;
8584
}
86-
.twig-component-render tbody th {
87-
font-weight: normal;
88-
}
89-
9085
.twig-component-render th:first-child,
9186
.twig-component-render tr:first-child {
9287
width: 25%;
9388
}
94-
.twig-component-render th {
89+
.twig-component-render th,
90+
.twig-component-render tbody th {
9591
font-weight: normal;
9692
}
9793
.twig-component-render th:first-child {
@@ -227,7 +223,7 @@
227223
<td>{{ component.name }}</td>
228224
<td>
229225
{% if component.class == 'Symfony\\UX\\TwigComponent\\AnonymousComponent' %}
230-
<pre class="sf-dump"><span class="text-muted">AnonymousComponent</span></pre>
226+
<pre class="sf-dump"><span class="text-muted">[Anonymous]</span></pre>
231227
{% else %}
232228
{{ profiler_dump(component.class_stub) }}
233229
{% endif %}
@@ -252,34 +248,37 @@
252248

253249
{% block table_renders %}
254250
<div class="twig-component-renders">
251+
{% set _memory = null %}
255252
{% for render in collector.renders %}
256253
<table class="twig-component-render" style="--render-depth:{{ render.depth }};">
257-
<thead class="sf-toggle {{ loop.index == 1 ? 'sf-toggle-on' : 'sf-toggle-off' }}"
258-
data-toggle-selector="#render-{{ loop.index }}--details"
259-
data-toggle-initial="{{ loop.index == 1 ? 'display' }}"
254+
<thead
255+
class="sf-toggle {{ loop.index == 1 ? 'sf-toggle-on' : 'sf-toggle-off' }}"
256+
data-toggle-selector="#render-{{ loop.index }}--details"
257+
data-toggle-initial="{{ loop.index == 1 ? 'display' }}"
260258
>
261259
<tr>
262260
<th class="key">{{ render.depth ? source('@TwigComponent/Collector/chevron-down.svg') }}{{ render.name }}</th>
263261
<th>
264262
{% if render.class == 'Symfony\\UX\\TwigComponent\\AnonymousComponent' %}
265-
<pre class="sf-dump"><span class="text-muted">[Anonymous] {{ render.name }}</span></pre>
263+
<pre class="sf-dump"><span class="text-muted">[Anonymous]</span></pre>
266264
{% else %}
267265
{{ render.class }}
268266
{% endif %}
269267
</th>
270268
<th class="cell-right renderTime">
271-
{% if render.render_memory %}
272-
{{ (render.render_memory / 1024 / 1024)|number_format(1) }}
273-
<span class="text-muted text-small">MiB</span>
274-
{% endif %}
269+
{% set _render_memory = render.render_memory|default(0) / 1024 / 1024 %}
270+
<span class="{{ _render_memory == _memory ? 'text-muted' }}">
271+
{{- _render_memory|number_format(1) -}}
272+
</span>
273+
<span class="text-muted text-small">MiB</span>
274+
{% set _memory = _render_memory %}
275275
</th>
276276
<th class="cell-right renderTime">
277277
{{ render.render_time|number_format(2) }}
278278
<span class="text-muted text-small">ms</span>
279279
</th>
280280
<th class="cell-right">
281281
<button class="btn btn-link toggle-button" type="button" aria-label="Toggle details">
282-
{{ source('@WebProfiler/Icon/chevron-down.svg', true) }}
283282
{{ source('@TwigComponent/Collector/chevron-down.svg') }}
284283
</button>
285284
</th>

0 commit comments

Comments
 (0)