Problem/Motivation
The release of Drupal 10.2.5 has introduced a regression in (but not limited to) Site Studio's implementation of CKEditor 5 that results in user input being lost if they type too fast.
- A user types into Standard install profile's "Article" node type's "body" field
- Uses the Drupal.editors.ckeditor5.onChange event to pull the value of the editor using ckInstance.getData() and store that in a JSON blob.
- Since this change https://git.drupalcode.org/project/drupal/-/commit/5540b5f84a6ae7899df01... if a user types multiple characters in quick succession, only the first character they type is registered in the on change event and all subsequent inputs are lost.
- I think the issue is due to the use of the immediate variable on the debounce call.
Steps to reproduce
If you paste this snippet into the JS console on a node page with a CKEditor instance and then type into the editor quickly vs slowly, you can see the issue. When typing quickly the onChange event is fired after the first user input but not fired again after the user types their last input.
Drupal.editors.ckeditor5.onChange(document.getElementById('edit-body-0-value'), () => {
const ckInstance = Drupal.CKEditor5Instances.values().next().value;
console.log(ckInstance.getData())
});
I've attached a video showing the above steps to test demonstrating the issue.
Proposed resolution
Remove the debounce from the onChange method. In that case, onChange will be called on each change immediately, and if the user/contrib code needs to throttle that, it is their responsibility, and they will be able to decide how much they want to throttle it.
Remaining tasks
Decide if removing debounce is viable. If it is, merge the PR.
User interface changes
None
Introduced terminology
None
API changes
The Drupal.editors.ckeditor5.onChange callback will no longer be throttled by itself. Nothing in core seems to be impacted performance-wise by this. In case the user code needs throttling, they should add it themselves.
For reference, for quite some time before https://www.drupal.org/project/drupal/issues/3396742, due to a mistake in the code, the changes were not throttled anyway, but just delayed by 400ms.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | ezgif-14371c08e1b419.gif | 619.23 KB | jaswinsingh |
| #11 | 3443422.patch | 602 bytes | 8ballsteve |
| #5 | d11typingfasteditorgif.gif | 723.33 KB | ankitv18 |
| #5 | d11fasttypingeditorissue.mov | 3.59 MB | ankitv18 |
| #3 | cke5 event typing speed.gif | 143.69 KB | wim leers |
Issue fork drupal-3443422
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jessebaker commentedComment #3
wim leersThis is a regression introduced by #3396742: CKEditor 5 doesn't save updated value if form submitted right after the change 😭
Let's get the (detailed, thank you!) steps to reproduce encoded in the
core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.phptest coverage that #3396742 expanded. We should be able to reproduce the failure in there.Reproduced easily without Site Studio, just by using a Drupal core text field. Rephrased the issue summary for that. This does not negatively impact Drupal core today, but impacts potentially many contrib modules.
Comment #5
ankitv18 commentedif debounce method is called with callback and delay only then it works perfectly.

Comment #6
rakun commentedHi @ankitv18
Did you provide patch for this since this branch looks empty?
Comment #8
ankitv18 commentedMR!8284 opened agaisnt 10.2.x branch, if this fix resolve the issue then we can push the commit to the 11.x branch too.
Comment #9
ankitv18 commentedComment #10
smustgrave commented11.x was correct target for the MR as a fix will have to land there first. I do see comment #8 but fix will have to pass 11.x too.
Tagging for issue summary as proposed solution appears to be missing. This a UI issue? If so can we add before/after there.
Also appears to be tagged for tests which may still be needed. Though with regressions (especially data loss) I'm a +1 for fixing and opening a follow up for expanding test coverage. But I can't make those calls.
Comment #11
8ballsteve commentedAdding the change from the MR as a patch so we can kick off some tests against this.
Comment #12
ok4p1 commentedHello, the patch mitigates the issue but I am still experiencing itTaking this back, I need to do more testing.
Comment #15
reinfate commentedI wonder if we could just get rid of debounce to fix this. (I pushed MR!10265 with that change)
Before the #3396742: CKEditor 5 doesn't save updated value if form submitted right after the change it worked just like without debounce, but with a 400ms delay for each call as mentioned in the issue summary there.
And IMO it just makes more sense, that onChange should be called on each change immediately, and if the user/contrib code needs to throttle that, it is their responsibility, and they will be able to decide how much they want to throttle it.
Comment #16
smustgrave commentedIssue summary still appears to need updating. Recommend using standard issue template.
Was previously tagged for tests but not sure what those would look like
Comment #17
reinfate commentedI expanded the
\Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5Test::testSaveto check the behaviour of the onChange event. The test assumes there will be no debounce/throttling from this method.Updated the IS
Back to "Needs review".
Comment #19
smustgrave commentedTest change looks good and summary is correct so removing those tags.
Following the steps am seeing the issue and MR does appear to addressed.
Comment #20
jaswinsingh commentedWe are facing a similar issue with the source editing plugin in Site Studio's component. The changes are not being applied to the component.
Comment #21
nod_let's go with removing debounce, the dependency needs to be removed as well.
Comment #22
maxdmayhew commentedI also am running into this issue on 10.4.6.
I have reported this to Acquia and honestly the workaround seems to be to go slow and wait 10 seconds or so before saving. The patch did not work for me.
Additionally, this seems more of an acquia specific issue in my testing. I am not experiencing this issue outside of the layout canvas.
Comment #23
jigariusI agree with maxdmayhew's comment #22. I think the issue is related to how Site Studio initializes its CKEditor instances. I don't get the issue outside Site Studio. I've created a support ticket with them but it seems they cannot reproduce the issue. If I have some time, I'll try to reproduce the error with a fresh Drupal install with just Site Studio on it.
For now, I've resorted to cheating with a custom event listener that triggers does an editor.setData(editor.getData()) when the user disables source editing mode. Some sources suggest that editor.fire("change:data") should help, however, it didn't work for me. IMHO, the issue probably stems from how Site Studio gets the data from the CKEditor widget.