Skip to content

Conversation

@wiewiurdp
Copy link
Contributor

@wiewiurdp wiewiurdp commented Mar 25, 2025

🎫 Issue IBX-9697

Related PRs:

Description:

Added profiler panel to twig-components

image

@wiewiurdp wiewiurdp changed the title IBX-9697:Adding profiler panel IBX-9697:Added profiler panel Mar 25, 2025
@wiewiurdp wiewiurdp requested a review from a team March 25, 2025 15:33
@adamwojs adamwojs changed the title IBX-9697:Added profiler panel IBX-9697: Added profiler panel Mar 26, 2025
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;

class TwigComponentCollector extends DataCollector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class TwigComponentCollector extends DataCollector
final class TwigComponentCollector extends DataCollector

@adamwojs
Copy link
Member

How does it look ? Could you please share screenshot ?

@@ -0,0 +1,42 @@
{% if collector.renderedComponents is not empty %}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link

@ViniTou ViniTou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compact always cause a little headache tho 😅

Ibexa\TwigComponents\DataCollector\TwigComponentCollector:
tags:
- name: ibexa.debug.data_collector
id: "ibexa.twig_components"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: "ibexa.twig_components"
id: 'ibexa.twig_components'

Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but I'm missing some minimal unit test coverage, maybe at least for that TwigComponentCollector, because I understand DefaultRenderer is more of e2e behat scope.

@wiewiurdp
Copy link
Contributor Author

compact always cause a little headache tho 😅

@ViniTou I added phpunit for this so you feel better :)

) {
$this->registry = $registry;
$this->eventDispatcher = $eventDispatcher;
$this->collector = $collector;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using events to collect data, as this would allow detaching this functionality from the DefaultRenderer instance (single responsibility pricinple and all that 😅).

Alternatively, consider creating TraceableDefaultRenderer that would maintain it's calls/data.

See Symfony\Component\Form\Extension\DataCollector\EventListener\DataCollectorListener for Symfony forms & event listening-based collection.

See Symfony\Component\HttpClient\TraceableHttpClient & Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector for Traceable variant.

use Ibexa\TwigComponents\Component\Event\RenderSingleEvent;
use Ibexa\TwigComponents\DataCollector\TwigComponentCollector;

final class TwigComponentCollectorListener
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can - should - use EventSubscriberInterface.

A general rule of thumb when picking whether you want to use subscriber or listener is flexibility. Listeners should be used if they need to be dynamically added / are generic enough to be attached to more events.

Also, consider using higher priority than normal (since you can use priorities for event listeners). We want to collect data early to prevent event propagation being stopped from impacting data collection.

@wiewiurdp wiewiurdp merged commit 0afcc7b into main Mar 27, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants