Problem/Motivation
After submitting a multi-step wizard-page form that uses Ajax, along with Dialog UI, and then using the Chrome browser back button to go back to the form, and then re-launching the modal wizard, I see a duplicate Next button that doesn't work.
From what I can tell, this may be a Drupal Core issue relating to dialog.ajax.js, though I have not tried to reproduce in other contexts. It appears to work correctly in Firefox, but is broken in Chrome and Edge.
Steps to reproduce
- New Drupal 9.5.9 install with Webform 6.1.5 enabled.
- Enable webform config Enable site-wide dialog support
- Create a page "Start page" with content
<p><a class="webform-dialog webform-dialog-narrow button" href="/form/test-multi-step-wizard">Launch the modal</a></p>
- Create a page "Confirmation page" with url alias "/confirmation-page"
- Create a new webform Test multi-step wizard with settings "Allow users to post submissions from a dedicated URL" and confirmation page URL alias "/confirmation-page"
- In the webform, turn on "Use AJAX"
- Webform Build export is
page_1:
'#type': wizard_page
'#title': 'Page 1'
page_one_question:
'#type': textarea
'#title': 'page one question'
page_2:
'#type': wizard_page
'#title': 'Page 2'
page_two_question:
'#type': textarea
'#title': 'Page two question'
page_3:
'#type': wizard_page
'#title': 'Page 3'
page_three_question:
'#type': textarea
'#title': 'page three question'
- Launch the webform from the Start Page node. (It opens in a Dialog UI.)
- Fill out each question, clicking the next button, and finally the Submit button.
- You are taken to the Confirmation page. Click the browser's back button.
- You are taken back to the Start page with the dialog closed. Click the button to open the dialog.
- Fill out the first question and hit "Next" to go to the next page.
- You now see the Next/Previous button of the current page, along with the original "Next" button from the previous page
Here is a screenshot of the broken state:
Proposed resolution
This is not a proposal for the resolution of the problem, but it is a workaround that I have found. Including this javascript on the Start page will force a full refresh of the page, which stops the problem from occurring, though it is a bit heavy-handed.
// Something about Dialog UI and Webform is not right. Navigating to the
// start page using the browser back button messes up the Dialog UI state,
// and causes certain Drupal.behaviors not to work correctly resulting in
// messed up buttons.
// Simply forcing a hard-refresh when using the back button solves the issue.
// @todo more closely check dialog.ajax.js to determine what exactly is
// getting messed up when using the back button in Chrome.
window.addEventListener("pageshow", function (event) {
const historyTraversal = event.persisted ||
(typeof window.performance != "undefined" &&
window.performance.navigation.type === 2);
if (historyTraversal) {
// Handle page restore.
window.location.reload();
}
});