From d1801c3d2c841fa76045f9a852bd85369ed968b4 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Mon, 16 Dec 2024 18:43:45 +0100 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20loading=20of=20WebProfilerBundle?= =?UTF-8?q?=E2=80=99s=20toolbar=20stylesheet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Resources/config/routing/wdt.xml | 2 +- Tests/Controller/ProfilerControllerTest.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Resources/config/routing/wdt.xml b/Resources/config/routing/wdt.xml index 26bbd964..9f45f1b7 100644 --- a/Resources/config/routing/wdt.xml +++ b/Resources/config/routing/wdt.xml @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd"> - + web_profiler.controller.profiler::toolbarStylesheetAction diff --git a/Tests/Controller/ProfilerControllerTest.php b/Tests/Controller/ProfilerControllerTest.php index 3933d30e..0e0a1e0a 100644 --- a/Tests/Controller/ProfilerControllerTest.php +++ b/Tests/Controller/ProfilerControllerTest.php @@ -152,15 +152,15 @@ public function testToolbarStylesheetActionWithProfilerDisabled() public function testToolbarStylesheetAction() { - $urlGenerator = $this->createMock(UrlGeneratorInterface::class); - $twig = $this->createMock(Environment::class); - $profiler = $this->createMock(Profiler::class); + $kernel = new WebProfilerBundleKernel(); + $client = new KernelBrowser($kernel); - $controller = new ProfilerController($urlGenerator, $profiler, $twig, []); + $client->request('GET', '/_wdt/styles'); + + $response = $client->getResponse(); - $response = $controller->toolbarStylesheetAction(); $this->assertSame(200, $response->getStatusCode()); - $this->assertSame('text/css', $response->headers->get('Content-Type')); + $this->assertSame('text/css; charset=UTF-8', $response->headers->get('Content-Type')); $this->assertSame('max-age=600, private', $response->headers->get('Cache-Control')); } From 979b623f12d1eb4f6f8f24fd321dfe1dee2444a2 Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Mon, 23 Dec 2024 18:25:21 +0100 Subject: [PATCH 2/2] [WebProfilerBundle] Fix event delegation on links inside toggles --- Resources/views/Profiler/base_js.html.twig | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Resources/views/Profiler/base_js.html.twig b/Resources/views/Profiler/base_js.html.twig index f8178106..839ea59d 100644 --- a/Resources/views/Profiler/base_js.html.twig +++ b/Resources/views/Profiler/base_js.html.twig @@ -122,6 +122,12 @@ } toggle.addEventListener('click', (e) => { + const toggle = e.currentTarget; + + if (e.target.closest('a, .sf-toggle') !== toggle) { + return; + } + e.preventDefault(); if ('' !== window.getSelection().toString()) { @@ -129,9 +135,6 @@ return; } - /* needed because when the toggle contains HTML contents, user can click */ - /* on any of those elements instead of their parent '.sf-toggle' element */ - const toggle = e.target.closest('.sf-toggle'); const element = document.querySelector(toggle.getAttribute('data-toggle-selector')); toggle.classList.toggle('sf-toggle-on'); @@ -154,14 +157,6 @@ toggle.innerHTML = currentContent !== altContent ? altContent : originalContent; }); - /* Prevents from disallowing clicks on links inside toggles */ - const toggleLinks = toggle.querySelectorAll('a'); - toggleLinks.forEach((toggleLink) => { - toggleLink.addEventListener('click', (e) => { - e.stopPropagation(); - }); - }); - toggle.setAttribute('data-processed', 'true'); }); }