Issue with Checkbox status on click and back button.

Created on 26 August 2025, 6 days ago

Problem/Motivation

When using facets checkbox widget, the checkbox status is wrongly changed when the user click because of the fix implemented for https://www.drupal.org/project/facets/issues/3210353 .

The checkbox get checked for an invisible fraction of time, then unckecked by the window.onbeforeunload.
https://www.drupal.org/project/facets/issues/3210353

This creates a bad user interaction, additionally window.onbeforeunload do not actually solve any issue since the all checkbox do not works after clicking the back button. (All the JS is not reexecuted)

Steps to reproduce

Click any checkbox and notice that it is unchecked until page reload. On clicking back, the checkbox status get updated as by expectation, however, no one checkbox then works.

Proposed resolution

The solution I am proposing is to use the even pageshow, that is executed after page load, but the event allow to check if the page is shown from the cache (e.persisted === true).

In this scenario, and when Drupal.facets is available. All the HTML created by JS (Checkbox + label) get removed and the behaviour reattached. This solution prevent the mishandling of the checkbox status on normal click, and fully restore the feature clicking the back button.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom marco.pagliarulo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024