- Issue created by @jv24
- Status changed to Needs review
about 1 month ago 2:08pm 12 March 2025 - πΊπΈUnited States jonraedeke
This patch is working really well. Thank you for doing this work, it's a major improvement. Previously, CKEditor5 was not triggering a change when "Run only on form change" was enabled.
One minor suggestion is to change the label for this option to "Run on form change" since it no longer uses "The interval to use for triggering autosave in milliseconds." setting when enabled.
- π©πͺGermany Fabianx
I reworked the approach in the following way:
- The autosaveFormMonitor was unreliable, so I switched strategy to check for changes before submitting the form
- I also re-added a debounce delay (inspired by the patch here), so that a save with skip_checks = TRUE is scheduled when changes are detected
- As there was always two save, I chose to ignore changes to autosave_last_autosave_form form keyTherefore:
We check for changes e.g. every 500 ms [interval check], but only submit the form if there are changes.
If debounceDelay is set then this save is debounced for 5 seconds. So as long as the user is typing, we don't autosave!
- TODO: Right now the debounceDelay is hard-coded to 5 seconds
Grok explanation:
Replaced the unreliable autosaveFormMonitor behavior with a robust hasFormChanges function for detecting form changes.
The new method compares current form values (formValues) against stored latestFormValues, excluding fields like autosave_form_last_autosave_timestamp via excludeFields, ensuring accurate detection of meaningful changes without relying on event-based monitoring.
This is implemented in triggerAjaxSubmitWithoutProgressIndication, where beforeSubmit uses hasFormChanges to decide if a save is needed, respecting onlyOnFormChange.
As an optional enhancement, I added debounceDelay (default: 5000ms) and debounceTimer to Drupal.autosaveForm. When set, it schedules saves after a delay only if no further changes occur, triggered with skip_checks = true. The form submit handler clears both interval and debounce timers to prevent conflicts. These changes remove Drupal.behaviors.autosaveFormMonitor, improve reliability, and support configurable debouncing via drupalSettings.autosaveForm.
Patch is attached, but still need to update the IS.