From 4485e2f9de2bb6726234a6cbd618e4958c2ab93e Mon Sep 17 00:00:00 2001 From: Alexander Hofbauer Date: Thu, 7 Aug 2025 13:53:11 +0200 Subject: [PATCH] [WebProfilerBundle] Fix toolbar not rendering after replacing it When the debug toolbar is replaced by newly loaded content, the parent element's ID has to be updated, else all queries for "'sfwdt' + token" cannot return a DOM element. --- .../Resources/views/Profiler/toolbar_js.html.twig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig index ab68c6d9f31bf..6d2930ff83253 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig @@ -538,11 +538,16 @@ 'sfwdt' + token, '{{ url("_wdt", { "token": "xxxxxx" })|escape('js') }}'.replace(/xxxxxx/, newToken), function(xhr, el) { + var toolbarContent = document.getElementById('sfToolbarMainContent-' + newToken); + /* Do nothing in the edge case where the toolbar has already been replaced with a new one */ - if (!document.getElementById('sfToolbarMainContent-' + newToken)) { + if (!toolbarContent) { return; } + /* Replace the ID, it has to match the new token */ + toolbarContent.parentElement.id = 'sfwdt' + newToken; + /* Evaluate in global scope scripts embedded inside the toolbar */ var i, scripts = [].slice.call(el.querySelectorAll('script')); for (i = 0; i < scripts.length; ++i) {