Some styles get added multiple times.

Created on 14 February 2023, over 1 year ago
Updated 29 September 2023, 9 months ago

Problem/Motivation

When classes are being added in BlockComponentRenderArraySubscriber, if there are multiple styles being added, every style except the last one get added multiple times.

The problem happens because the $grouped_classes variable is defined outside of the loop through each style. During each loop, the new classes are merged into the $grouped_classes variable, which is then merged into $build['#attributes']['class'].

Steps to reproduce

  1. Add two style groups.
  2. Add one or more styles to each group.
  3. Add each created style to be available for a single block type.
  4. Add the block via Layout Builder and select a style from each group.
  5. Observe in the rendered HTML that one or more of the classes is repeated.

Proposed resolution

Don't merge $grouped_classes into $build['#attributes']['class'] until after the loop.

Remaining tasks

  1. Refactor code
  2. Test
  3. Write a test?

User interface changes

Nope

API changes

Nope

Data model changes

Nope

πŸ› Bug report
Status

Postponed: needs info

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States pyrello

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

Comments & Activities

  • Issue created by @pyrello
  • @pyrello opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States pyrello

    Not sure that the test that queued itself up has any chance of being successful or not, since it appears to be combining Drupal 10.1 with PHP 5.3. I set another one to run.

    This works for me. Not sure if a test is required or not. Adding a patch file so I can start using it already.

  • Assigned to ricksta
  • πŸ‡ΊπŸ‡ΈUnited States ricksta
  • Issue was unassigned.
  • πŸ‡ΊπŸ‡ΈUnited States ricksta

    I'd like to be able to test the patch. But I've followed the "Steps to reproduce" and I can't reproduce the bug.

  • πŸ‡ΊπŸ‡ΈUnited States daddison

    I've also followed the "Steps to reproduce" and I also can't reproduce the bug.

  • Status changed to Postponed: needs info 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mmarler
Production build 0.69.0 2024