cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x]: Content vanishes from fields of a contentBlock field when resetting to a previous revision

Open MariusKnirk opened this issue 2 months ago • 5 comments

What happened?

Description

Fields (CKEditor and plain text) inside a contentBlock field inside a nested matrix field are lose their content when switching to a previous revision. The content cannot be recovered by switching to any other revision now. We observed this bug on the versions 5.8.20 and 5.8.21. However, we cannot reproduce it with any contentBlock fields or entries created on these versions.

Steps to reproduce

As mentioned in the description, using Craft 5.8.20 and 5.8.21 we could not reproduce this behavior manually with any contentBlock fields. We only have certain entries (existing prior to updating to those versions) in the system where it happens.

Where we observe it

The behavior can be observed before and after pruning all revisions or resaving all entries. Entries in a section of type structure containing a contentBlock field (containing two CKEditor fields) inside a nested matrix field. When adding a plain text field to that existing contentBlock field its content also vanishes.

What we tried to reproduce

Whether using a newly created contentBlock field or the one we already have, whether outside a matrix field, inside a matrix field or inside a nested matrix field, whether in the same entries or different entries (newly created or not), whether in a channel or a structure section, nothing leads to reproducing this behavior. It only happens in those already existing contentBlock fields in already existing entries.

Expected behavior

All fields have the content corresponding to that revision.

Actual behavior

Fields (CKEditor and plain text) inside a contentBlock field inside a nested matrix field are missing their content. The content cannot be recovered by switching to any other revision now.

Craft CMS version

5.8.20 and 5.8.21

PHP version

8.3

Operating system and version

No response

Database type and version

MySQL 8.0

Image driver and version

No response

Installed plugins and versions

  • CKEditor 4.11.0
  • CP Field Inspect 2.0.4
  • Elements Panel 3.0.1
  • Feed Me 6.11.0
  • Formie 3.1.6
  • Ray 2.1.1
  • SEO 5.0.0
  • Vite 5.0.1

MariusKnirk avatar Dec 08 '25 13:12 MariusKnirk

CMS-1716

linear[bot] avatar Dec 08 '25 13:12 linear[bot]

Hi, thanks for getting in touch!

Could you please clarify a few things? You have a section with an entry type that has a Matrix field, and that Matrix field contains a Content Block field, which in turn contains CKEditor and Plain Text fields - correct?

What are the settings of that Matrix field? Which view mode does it use? Is "Enable versioning for entries in this field" turned on?

Do you have a single or multi-site setup?

Fields (CKEditor and plain text) inside a contentBlock field inside a nested matrix field are lose their content when switching to a previous revision.

Do you mean you don’t see the plain text field’s content when you view a revision, or that when you revert to a revision, the content is not brought back?

Do you know which version the affected entries were created or updated on?

i-just avatar Dec 09 '25 09:12 i-just

Could you please clarify a few things? You have a section with an entry type that has a Matrix field, and that Matrix field contains a Content Block field, which in turn contains CKEditor and Plain Text fields - correct?

We have a section with an entry type that has a Matrix field, and that Matrix field contains another Matrix field, that second Matrix field contains an entry type with a Content Block field, which in turn contains CKEditor and Plain Text fields. More information at the bottom.

What are the settings of that Matrix field? Which view mode does it use? Is "Enable versioning for entries in this field" turned on?

It is in "inline editing" mode. "Enable versioning for entries in this field" was disabled, but the bug remains with it enabled. See further down.

Do you have a single or multi-site setup?

It is a multi-site setup.

Do you know which version the affected entries were created or updated on?

No.

Fields (CKEditor and plain text) inside a contentBlock field inside a nested matrix field are lose their content when switching to a previous revision.

Do you mean you don’t see the plain text field’s content when you view a revision, or that when you revert to a revision, the content is not brought back?

When viewing and reverting to a revision, the content just vanishes, as in the fields are empty, although they did have content in that revision. And reverting to any other revision won't restore that content.
Through your comment I decided to do some further testing and finally found the steps to reproduce the behavior manually in our system. Our system/set up:

  • Craft CMS 5.8.21
  • Multi-site setup
  • Section "Pages" with an entry type "Page"
  • "Page" contains a matrix field called "Sections"
    • "Sections" has the entry types "Section", "Section with Icon" and "Expandable Section"
    • "Enable versioning for entries in this field" is enabled
    • "View Mode" = "As inline-editable blocks"
  • All three of those entry types contain the matrix field "Section Content Blocks"
    • "Enable versioning for entries in this field" is enabled
    • "View Mode" = "As inline-editable blocks"
    • "Section Content Blocks" has an entry type "Text" containing a Content Block field called "Headline + Text"
      • "Headline + Text" has the "View Mode" = "Grouped"
      • "Headline + Text" contains any combination of CKEditor or Plain Text fields. In our case its a Plain Text field "Headline" and a CKEditor field "Text".

Now to reproduce:

  1. Create a new entry in the "Pages" section called "Test Page".
  2. Create a new "Section" entry in the "Sections" matrix field.
  3. Inside that "Section" entry, create a new "Text" entry and fill the "Headline + Text" fields with content.
  4. Save "Test Page".
  5. Edit the contents of the "Headline + Text" fields and save "Test Page" to create a new revision.
  6. View and revert to that revision. All content is restored from that revision as expected.
  7. Now, inside that same first "Section" entry, create another new "Text" entry and fill the "Headline + Text" fields with content.
  8. Save "Test Page".
  9. Edit the contents of the first and second "Headline + Text" fields and save "Test Page" to create a new revision.
  10. View and revert to that revision. Both "Headline + Text" fields are completely empty. Reverting to any other revision containing the second "Headline + Text" field will not bring back the contents to those fields.

MariusKnirk avatar Dec 09 '25 14:12 MariusKnirk

Thanks for the extra info! I was able to reproduce this and raised a PR.

The key to reproducing was that the Content Block field needs to be inside of a matrix field (just one level will do), that matrix field has to use the inline-editable blocks view mode, and there have to be at least two “blocks” in that field. Other view modes are not affected. Also, the issue is with retrieving and displaying the data in that particular view mode, not with revisions missing content in the database. For now, if you wish, you can switch to, e.g. cards view mode, and the data from past revisions should be visible there.

i-just avatar Dec 10 '25 10:12 i-just

Thank you for the quick response and the insight!

MariusKnirk avatar Dec 10 '25 11:12 MariusKnirk