Skip to content

Commit 4cf595c

Browse files
Include panel scripts in content when RENDER_PANELS=True (#1689)
* Include panel scripts in content when RENDER_PANELS=True * Make the panel scripts async module scripts. Without marking them as modules, they weren't being loaded in as expected. Co-authored-by: Tim Schilling <[email protected]>
1 parent 7a8920c commit 4cf595c

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

debug_toolbar/templates/debug_toolbar/includes/panel_content.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ <h3>{{ panel.title }}</h3>
88
</div>
99
<div class="djDebugPanelContent">
1010
{% if toolbar.should_render_panels %}
11+
{% for script in panel.scripts %}<script type="module" src="{{ script }}" async></script>{% endfor %}
1112
<div class="djdt-scroll">{{ panel.content }}</div>
1213
{% else %}
1314
<div class="djdt-loader"></div>

tests/test_integration.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
rf = RequestFactory()
3535

3636

37+
def toolbar_store_id():
38+
def get_response(request):
39+
return HttpResponse()
40+
41+
toolbar = DebugToolbar(rf.get("/"), get_response)
42+
toolbar.store()
43+
return toolbar.store_id
44+
45+
3746
class BuggyPanel(Panel):
3847
def title(self):
3948
return "BuggyPanel"
@@ -213,13 +222,8 @@ def test_html5_validation(self):
213222
raise self.failureException(msg)
214223

215224
def test_render_panel_checks_show_toolbar(self):
216-
def get_response(request):
217-
return HttpResponse()
218-
219-
toolbar = DebugToolbar(rf.get("/"), get_response)
220-
toolbar.store()
221225
url = "/__debug__/render_panel/"
222-
data = {"store_id": toolbar.store_id, "panel_id": "VersionsPanel"}
226+
data = {"store_id": toolbar_store_id(), "panel_id": "VersionsPanel"}
223227

224228
response = self.client.get(url, data)
225229
self.assertEqual(response.status_code, 200)
@@ -444,7 +448,7 @@ def test_view_returns_template_response(self):
444448
self.assertEqual(response.status_code, 200)
445449

446450
@override_settings(DEBUG_TOOLBAR_CONFIG={"DISABLE_PANELS": set()})
447-
def test_intcercept_redirects(self):
451+
def test_intercept_redirects(self):
448452
response = self.client.get("/redirect/")
449453
self.assertEqual(response.status_code, 200)
450454
# Link to LOCATION header.
@@ -464,6 +468,15 @@ def test_server_timing_headers(self):
464468
for expected in expected_partials:
465469
self.assertTrue(re.compile(expected).search(server_timing))
466470

471+
@override_settings(DEBUG_TOOLBAR_CONFIG={"RENDER_PANELS": True})
472+
def test_timer_panel(self):
473+
response = self.client.get("/regular/basic/")
474+
self.assertEqual(response.status_code, 200)
475+
self.assertContains(
476+
response,
477+
'<script type="module" src="/static/debug_toolbar/js/timer.js" async>',
478+
)
479+
467480
def test_auth_login_view_without_redirect(self):
468481
response = self.client.get("/login_without_redirect/")
469482
self.assertEqual(response.status_code, 200)

0 commit comments

Comments
 (0)