Some styles get added multiple times.

Created on 14 February 2023, almost 2 years ago
Updated 29 September 2023, about 1 year 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

Production build 0.71.5 2024