Problem/Motivation
When using LazyBuilder, generated placeholders are merged with BubbleableMetadata::mergeAttachments()
, where the previously created placeholders are appended to the newly created once. This seems to be counter intuitive, as one would expect the ordering of placeholders would match the order in which they are created.
As an example - having two paragraphs attached to a reference field, where each paragraph results in a placeholder being build, when the field is displayed, the second paragraph will eventually be rendered before the first one. If anywhere in the code there is a check for previously rendered content - it fails because the rendering order is not preserved.
Steps to reproduce
I was able to reproduce this behavior on a clean D10, with Paragraphs, Views Reference and Views Exclude Previous installed, in a classic "Featured Content" scenario, where the content displayed in a view at the top of the page should be excluded from a view displayed below. To see the issue - user Lazy Builder formatter for the Views Reference field.
Proposed resolution
Unless there is a specific reason to have a reverse order for placeholders, I suggest changing places for variables on the line 159 in BubbleableMetadata::mergeAttachments()
:
public static function mergeAttachments(array $a, array $b) {
...
$placeholders = $a['placeholders'] + $b['placeholders'];
...
}
to
public static function mergeAttachments(array $a, array $b) {
...
$placeholders = $b['placeholders'] + $a['placeholders'];
...
}
Remaining tasks
Discuss, and approve.
User interface changes
None
API changes
None
Data model changes
None