Closed (fixed)
Project:
CKEditor 5
Version:
1.0.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
20 Aug 2021 at 20:56 UTC
Updated:
19 Nov 2021 at 13:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersExcellent find! Will raise this in the meeting we have with the CKE5 team this Thursday! 😊
Comment #3
wim leersBumping priority because this is a form of data loss.
Comment #4
wim leersFYI: We ran out of time before we got to this one. Will discuss it next time.
Comment #5
wim leersCould you please report this at https://github.com/ckeditor/ckeditor5/issues? 🙏
(If you don't, that's fine, I'll do so when I get back from vacation!)
Comment #6
rkollerSure you dont have to deal with that before your vacation. will write up and create issues later tonight or tomorrow (for this issue and the other one you also asked for an upstream report). Just one brief question. Shall i retest with the latest version of the ckeditor5 contrib module upfront if the issue still persists and then reference the git id of the dev version and mention that it was found and tested in drupal9? or what would be the best, helpful and preferred procedure for the upstream devs?
p.s. enjoy your vacation! :)
Comment #7
rkollerWent ahead since I had a bit of free time to write up both issues you've asked for. Issue could be found over here: https://github.com/ckeditor/ckeditor5/issues/10505
p.s. the only thing i was unsure how to report and write was the `installed CKEditor plugins` part. I've just mentioned the listed dev dependencies in the CKEditor 5 modules package.json:
is that correct or completely wrong? :D or are there others?
Comment #8
wim leersThank you!!! 🤗🙏
Comment #9
wim leersIt's going to be released today, October 26: https://github.com/ckeditor/ckeditor5/issues/10637. Let's wait for that :)
Comment #11
wim leersMarked #3245845: Changing code in Source Editing mode is not saved unless switched back out of Source Editing first as a duplicate. Transferring issue credit.
Comment #13
tim.plunkettThanks, not sure how I missed this one before opening.
Comment #14
wim leers#3245942: Update CKEditor 5 to 31.0.0 will update our CKE5 build to today's release, that should fix this!
Comment #15
wim leersTurns out that this is not actually fixed yet in CKEditor 5 31.0.0. Even using the exact steps to reproduce that @rkoller posted upstream. Very unfortunate.
Also https://github.com/ckeditor/ckeditor5/issues/10505#issuecomment-952086969
Comment #16
rkoller@wim-leers hm i've installed ck5 in a sandbox installation of drupal 9.3.x-dev and applied the merge request 141 with Claro as the admin theme. i would say it works half way. it works for entities not created yet but as soon as an entity is saved it doesn't work anymore. (already wanted to intervene and say it works on my end but i did one detail differently which i've noticed afterwards now. perhaps that detail helps debugging)
if you go through the eight steps described in https://github.com/ckeditor/ckeditor5/issues/10505 the bug persists. but create a new article.
then enter the three words and change their styling to bold. but instead of saving and opening the article again you directly switch to the source editor and proceed with changing the markup that only one or two words are styled in bold. you then hit save and you notice that those entries are actually saved. but if you go back to the source editor now and try to change the markup again the new changes arent saved anymore. so the functionality is basically there for ckeditor5 otherwise it wouldnt work for new nodes on the first save?
Comment #17
wim leersOver at https://github.com/ckeditor/ckeditor5/issues/10505#issuecomment-952211184 a CKEditor 5 developer said that
editor.getData()works fine.I can confirm that this is the case in Drupal too.
Drupal.editors.ckeditor5.detach()does this:I suspect this is the problem.
I just had a meeting with the CKEditor 5 team, and they were surprised we're even doing that. @zrpnr added that all the way in January, when this module was still getting kickstarted. So no idea what the rationale is.
We were told to remove that
editor.updateSourceElement();(EDIT: maybe for in-place editing? 🤔) and it should work fine … but it does not. 😢Both with and without that line, I can confirm that:
editor.getData()$x('//textarea')[1]both return the correct data. But still either with or without that line, the data does not get saved. I can also confirm that by looking at the
POSTrequest: its headers still contain the old data.Something really weird is going on. @lauriii to the rescue!
Comment #19
lauriiiI did some research on this, and in the end, I was able to figure out the root cause for this.
First, I was trying to figure out whether
Drupal.editors.ckeditor5.detach()had something to do with that. Simply removing that didn't fix it, so I had to dig deeper.I attached an event listener for
submitand I was able to confirm that the updated value was in the form field at this point in both, Drupal, and in a minimal setup of CKEditor. After that, I attached another event listener toformdataevent. By doing that I was able to point that in Drupal, the field value had been reverted betweensubmitandformdataevents. 🤯 However, in the minimal setup of CKEditor, the field value was retained between the events.I set a breakpoint on the CKEditor 5 detach behavior to find out what was happening. I was quickly able to point out that
Drupal.editorDetachwas reverting the field value back to it's original state, becausedata-editor-value-is-changedwas still set at false. 😐I figured that the
data-editor-value-is-changedwas being set ononChangecallback which Drupal editors are required to supply.In the CKEditor 5 code, that was mapped to
change:dataon the CKEditor 5 model. At first I thought that there must be a problem on the CKE side and the event wasn't being triggered in source mode. However, that's wasn't the case. The event was triggered correctly and even at the correct time.It turned out that it actually was a race condition, which was caused by our CKEditor 5 initialization code decorating the
onChangecallback with debounce. 😅This means that in the end, it turns out it's completely on our side, we simply have to avoid decorating the callback with debounce when the callback is being called in source editing mode (which indicates that the form must be submitting too, because that's the only condition when the model is being updated when in source editing mode).
Sadly, I didn't manage to write test coverage for this within reasonable amount of time, given all the magic that is happening in the source editing mode. 😢
Comment #21
rkollerufff that sounds tricky to debug. I've applied the diff and tested all the scenarios. at the beginning there was just one hickup until i've noticed that i forgot to clear the caches. but afterwards i was able to make changes to the markup in the source view and directly save and in each scenario i've tried the changes got saved and displayed properly in the frontend afterwards. :) (*i've tried with 9.3.0-alpha1)
Comment #22
wim leersA debounced change event conflicting through a race condition only when submitting directly from
SourceEditing, just for editor-switching XSS protection … wow 🤯🤣Comment #23
wim leers🚢
Comment #24
wim leers