BubbleableMetadata appears to be merging placeholdes in a wrong order.

Created on 2 January 2024, 12 months ago
Updated 5 May 2024, 8 months ago

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

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
RenderΒ  β†’

Last updated about 8 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States euk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024