Issue Bug Closed

#110957CKEditor 5 may initialize with a truncated value when the edit form is loaded slowly; saving then loses the rest of the text

Dennis Füllgraf 10/08/26, 10:12 updated 11/07/26, 22:13

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.js is 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.
  • RichTextElement renders the value as the text content of <textarea slot="textarea">.
  • firstUpdated() calls initCKEditor() as soon as the textarea element exists, or on slotchange. ClassicEditor.create() then reads textarea.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:

  1. 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>.
  2. Serve it from a small server that sends the response up to the middle of the textarea content, pauses, and then sends the rest.
  3. 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

  1. Georg Ringer commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-10-10T05:20:10+00:00" > 10/10/26, 05:20 </span>

    Applied in changeset commit:d01474b641035076b02e398dd6e431be6a0446a6.

  2. Gerrit Code Review pushed patch set 1 for 13.4 to change 96708 status Resolved Under Review <span data-processor="relativetime" data-value="2026-10-15T08:15:12+00:00" > 10/15/26, 08:15 </span>

  3. Benni Mack commented and changed status Under Review Closed <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.