From 47ef65f336dc8c6637b050859a3a15f63ba8aac7 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 10 May 2021 15:41:36 -0400 Subject: [PATCH] only load Sfjs if it is not present Plus, avoid loading the toolbar if it is no longer on the page --- .../Resources/views/Profiler/base_js.html.twig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig index c6631376d2..f70bfc01c3 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig @@ -5,6 +5,7 @@ them as JavaScript source code. Always use '/*' comments instead of '//' comments to avoid impossible-to-debug side-effects #} +if (typeof Sfjs === 'undefined') { Sfjs = (function() { "use strict"; @@ -424,6 +425,10 @@ 'sfwdt' + token, '{{ url("_wdt", { "token": "xxxxxx" })|escape('js') }}'.replace(/xxxxxx/, newToken), function(xhr, el) { + /* Do nothing in the edge case where the toolbar has already been replaced with a new one */ + if (!document.getElementById('sfToolbarMainContent-' + newToken)) { + return; + } /* Evaluate in global scope scripts embedded inside the toolbar */ var i, scripts = [].slice.call(el.querySelectorAll('script')); @@ -799,5 +804,5 @@ Sfjs.createTabs(); Sfjs.createToggles(); }); - +} /*]]>*/