Skip to content

Conversation

i-just
Copy link
Contributor

@i-just i-just commented Jun 19, 2025

Description

In some cases, the lazy eager loading for the matrix field in inline-editable blocks mode was only finding elements owned by the first nested entry (block).

When getting blocks for the matrix field in the inline-editable blocks mode, we use lazy eager loading: https://github.com/craftcms/cms/blob/5.7.10/src/fields/Matrix.php#L934

When the time came to find the target elements, the query had the ownerId parameter set to the ID of the first entry (block) we were eager loading for, which caused the results to be incorrectly limited by that ownerId.

Steps to reproduce:

  • create matrix - blocks 3 Matrix field (inline-editable blocks view mode) with an entry type that can have only the title
  • create matrix - blocks 2 Matrix field (inline-editable blocks view mode) with an entry type that contains the matrix - blocks 3 field; make the matrix - blocks 3 field required;
  • create matrix - blocks 1 Matrix field (inline-editable blocks view mode) with an entry type that contains matrix - blocks 2 field
  • create a section with an entry type that contains the matrix - blocks 1 field
  • create an entry in the section from the previous step
    • add one matrix - blocks 1 block, title: ”c1“;
    • in it add two matrix - blocks 2 blocks, one with title ”c1.1“, the other with title ”c1.2“;
    • to the ”c1.1“ block add one matrix - blocks 3 block with title ”c1.1.1“;
    • to the ”c1.2“ block add one matrix - blocks 3 block with title ”c1.2.1“;
    • fully save & continue editing
  • add another matrix - blocks 2 block and try to save
  • a validation error will prevent the save (title and matrix - blocks 3 are required)
  • notice that in the ”c1.2“ block, the content for the matrix - blocks 3 is missing; if you reload the page, it'll appear again

Related issues

n/a - reported by @tommysvr

@i-just i-just requested a review from brandonkelly June 19, 2025 15:00
@brandonkelly brandonkelly merged commit fdaf356 into 5.x Jun 24, 2025
2 checks passed
@brandonkelly brandonkelly deleted the bugfix/nested-matrix-blocks-and-eagerly branch June 24, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants