cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x]: Nested, inline-editable Matrix field with "Min entries" set get recursively created on edit page pageload

Open mmikkel opened this issue 1 year ago • 1 comments

What happened?

Description

If an inline-editable Matrix field, with "Min entries" set to 1 and only a single entry type selected, is added to its own entry type (i.e. the field is nested within itself), nested entries are recursively created when the edit page loads. It's also impossible to save the entry.

...I get that this is an odd thing to do – but I wanted to see what would happen if I did, and the results are interesting 🙂

Steps to reproduce

  1. Create a Matrix field. Set the "Min entries" setting to 1 and "View Mode" to "As inline-editable blocks". Create a new entry type for the Matrix field via the "Create" button, but don't add any fields to the entry type yet. Save the field.

  2. Edit the entry type that was just created; adding the same Matrix field to its field layout.

  3. Add the Matrix field to a section entry type's field layout (or, add the same entry type the Matrix field uses, to a section).

  4. Create an entry in that section, and observe that nested entries are created ad infinitum whenever the edit page is loaded. Most of the time only 2 or 3 nested entries are created, sometimes it actually keeps going, creating nested entries indefinitely in a loop (although I have trouble reliably reproducing that)

https://github.com/craftcms/cms/assets/298510/32fc0edb-5fc8-49e0-bca3-03a7467bd529

Expected behavior

I'm not sure!

Actual behavior

A number of nested entries get created every time the edit page is loaded.

Craft CMS version

5.0.0-beta.1

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

mmikkel avatar Feb 10 '24 22:02 mmikkel

Hmmmm, I’m not sure what we could do about this as you’ve created an impossible content model. Even if Matrix weren’t to automatically create those nested blocks, you’ll never be able to get the entry to a state where it validates.

brandonkelly avatar Feb 11 '24 16:02 brandonkelly