#110957CKEditor 5 may initialize with a truncated value when the edit form is loaded slowly; saving then loses the rest of the text
Description
Problem
When a record with a long RTE field is opened over a slow or unstable connection, CKEditor 5 sometimes contains only the first part of the field value. When the record is saved, CKEditor writes this truncated value back to the textarea. The rest of the text is then lost, even if the editor only changed other fields, such as the teaser or the date.
We observed this on 13.4.35 in Chrome, Edge and Firefox. Over six months it happened to several editors and dozens of news records. In sys_history it shows up clearly: the new bodytext is an exact prefix of the old one, often cut in the middle of a word, with the HTML closed properly.
Cause
- The module
EXT:rte_ckeditor/Resources/Public/JavaScript/ckeditor5.jsis emitted as<script type="module" async>in the<head>. If the module comes from the browser cache, it runs while the document is still being parsed. RichTextElementrenders the value as the text content of<textarea slot="textarea">.firstUpdated()callsinitCKEditor()as soon as the textarea element exists, or onslotchange.ClassicEditor.create()then readstextarea.value.
If the HTML response stalls while the parser is inside the textarea, the editor is created with the part of the value received so far. The rest of the text is parsed into the textarea afterwards. CKEditor overwrites the textarea on submit, so the truncated content is what gets saved.
Source: Build/Sources/TypeScript/rte-ckeditor/ckeditor5.ts (firstUpdated() / initCKEditor()), unchanged in main and 13.4.
How to reproduce
We reproduced it in isolation:
- Build a page that loads the original
ckeditor5.js(13.4.35) the same way FormEngine does: importmap and<script type="module" async>in<head>, then<typo3-rte-ckeditor-ckeditor5><textarea slot="textarea">…long HTML…</textarea></typo3-rte-ckeditor-ckeditor5>. - Serve it from a small server that sends the response up to the middle of the textarea content, pauses, and then sends the rest.
- After load, compare
editor.getData()and the submitted textarea value with the original value.
Result, three runs per pause length:
- Pause of 0 / 20 / 50 / 100 / 200 ms: value complete.
- Pause of 400 ms and 1.5 s: value truncated every time, at the point where the response paused.
Within TYPO3, a long bodytext combined with a slow or lossy connection should show the same behaviour. A short stall during the transfer is enough.
Suggested fix
Wait for the document to be parsed before reading the textarea. This adds no delay for elements inserted later, such as inline records loaded via AJAX, because readyState is no longer loading at that point.
protected async initCKEditor(): Promise<void> {
if (!(this.target[0] instanceof HTMLTextAreaElement)) {
throw new Error('No rich-text <textarea> content target found.');
}
// The textarea content may still be streaming in while the document is being parsed
if (document.readyState === 'loading') {
await new Promise<void>((resolve) => document.addEventListener('DOMContentLoaded', () => resolve(), { once: true }));
}
// …
We have been running this change as a patch on 13.4.35 in production. With it, the isolated test above stayed complete in 12 of 12 runs, including a 1.5 s pause.
Environment
TYPO3 13.4.35 (composer mode), PHP 8.2, Production context. Not checked on 12.4.
Reviews 3
History 27
-
Gerrit Code Review pushed patch set 1 for main to change 96541 status
NewUnder Review <span data-processor="relativetime" data-value="2026-10-08T20:35:01+00:00" > 10/08/26, 20:35 </span> -
Gerrit Code Review pushed patch set 2 for main to change 96541 <span data-processor="relativetime" data-value="2026-10-09T08:51:59+00:00" > 10/09/26, 08:51 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 96541 <span data-processor="relativetime" data-value="2026-10-09T09:09:31+00:00" > 10/09/26, 09:09 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 96584 <span data-processor="relativetime" data-value="2026-10-10T05:07:17+00:00" > 10/10/26, 05:07 </span>
-
Georg Ringer commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-10-10T05:20:10+00:00" > 10/10/26, 05:20 </span> -
Gerrit Code Review pushed patch set 1 for 13.4 to change 96708 status
ResolvedUnder Review <span data-processor="relativetime" data-value="2026-10-15T08:15:12+00:00" > 10/15/26, 08:15 </span> -
Benni Mack commented and changed status
Under ReviewClosed <span data-processor="relativetime" data-value="2026-11-07T22:13:34+00:00" > 11/07/26, 22:13 </span>wont do in v13, but v14+ is covered.
Applied in changeset commit:d01474b641035076b02e398dd6e431be6a0446a6.