Skip to content

Commit f571734

Browse files
novucstim-schilling
authored andcommitted
Stop the history panel buttons from submitting their forms
Both buttons sit in a form and carry no type, so they default to submit. They only avoid navigating because history.js calls preventDefault, and that script loads with the panel, so a click landing first sends the browser to the raw JSON of the sidebar or refresh view. The toolbar is then gone from the page, which is what the switch test hit on CI. The forms are read by ajaxForm rather than submitted, so nothing needs the submit behaviour. Clicking early is now a no-op instead, so the test retries the click until the switch takes effect.
1 parent b63f4fa commit f571734

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

debug_toolbar/templates/debug_toolbar/panels/history.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% load i18n static %}
22
<form method="get" action="{% url 'djdt:history_refresh' %}">
33
{{ refresh_form.as_div }}
4-
<button class="refreshHistory">Refresh</button>
4+
<button type="button" class="refreshHistory">Refresh</button>
55
</form>
66
<table class="djdt-max-height-100">
77
<thead>

debug_toolbar/templates/debug_toolbar/panels/history_tr.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<td class="djdt-actions">
4545
<form method="get" action="{% url 'djdt:history_sidebar' %}">
4646
{{ history_context.form.as_div }}
47-
<button data-request-id="{{ request_id }}" class="switchHistory">Switch</button>
47+
<button type="button" data-request-id="{{ request_id }}" class="switchHistory">Switch</button>
4848
</form>
4949
</td>
5050
</tr>

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Pending
1313
parameters.
1414
* Fixed the error shown when panel content fails to load, which could not
1515
find the toolbar window inside the shadow root.
16+
* Stopped the history panel buttons from submitting their form when clicked
17+
before the panel script has loaded, which navigated away from the page.
1618

1719
7.0.0 (2026-06-17)
1820
------------------

tests/test_integration.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,16 +788,30 @@ def test_rerender_on_history_switch(self):
788788
self.get("/regular_jinja/basic")
789789
# Make a new request so the history panel has more than one option.
790790
self.get("/execute_sql/")
791-
template_panel = self.selenium.find_element(By.ID, HistoryPanel.panel_id)
792791
# Record the current side panel of buttons for later comparison.
792+
previous_request_id = self.selenium.find_element(
793+
By.ID, "djDebug"
794+
).get_attribute("data-request-id")
793795
previous_button_panel = self.selenium.find_element(
794796
By.ID, "djDebugPanelList"
795797
).text
796798

797799
# Click to show the history panel
798800
self.selenium.find_element(By.CLASS_NAME, HistoryPanel.panel_id).click()
801+
799802
# Click to switch back to the jinja page view snapshot
800-
list(template_panel.find_elements(By.CSS_SELECTOR, "button"))[-1].click()
803+
def switch_to_oldest_snapshot(selenium):
804+
buttons = selenium.find_element(By.ID, HistoryPanel.panel_id).find_elements(
805+
By.CSS_SELECTOR, ".switchHistory"
806+
)
807+
if buttons:
808+
buttons[-1].click()
809+
return (
810+
selenium.find_element(By.ID, "djDebug").get_attribute("data-request-id")
811+
!= previous_request_id
812+
)
813+
814+
self.wait.until(switch_to_oldest_snapshot)
801815

802816
current_button_panel = self.selenium.find_element(
803817
By.ID, "djDebugPanelList"

0 commit comments

Comments
 (0)