Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#50508 closed defect (bug) (fixed)

Customize: Widgets appear "inactive" by default

Reported by: afercia's profile afercia Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version: 5.5
Component: Customize Keywords: has-screenshots has-patch
Focuses: javascript Cc:

Description

This appear to be a regression in trunk. I was able to reproduce on two different machines.

  • latest trunk
  • no plugins active, Twenty Twenty theme
  • make sure there are some Widgets added in the theme's widget areas
  • go to the Customizer > Widgets > one of the widget areas e.g. the Twenty Twenty "Footer 1"
  • observe all the Widgets listed in the left sidebar look "inactive" their container gets a CSS opacity: 0.5
  • observe it happens also in "reorder mode"
  • all widget boxes are fully functional, they just appear "inactive" because of the opacity - they also have an insufficient color contrast
  • compare with latest WordPress stable, where the listed widgets don't get the opacity
  • to my understanding, the opacity should only be set on the widgets that are _not_ rendered
  • something wrong appears to happen with the widget-rendered class, which isn't applied

See attached screenshot, from left to right:

  • trunk: widgets list normal mode
  • trunk: widgets list "reorder" mode
  • 5.4: widgets list normal mode

Attachments (4)

50508.png (181.4 KB) - added by afercia 4 years ago.
50508.diff (546 bytes) - added by dlh 4 years ago.
50508.2.diff (2.3 KB) - added by SergeyBiryukov 4 years ago.
50508.3.diff (2.6 KB) - added by dlh 4 years ago.

Download all attachments as: .zip

Change History (9)

@afercia
4 years ago

This ticket was mentioned in Slack in #themereview by joyously. View the logs.


4 years ago

@dlh
4 years ago

#2 follow-up: @dlh
4 years ago

  • Keywords has-patch added

Introduced, I think, in [47550] with the change to a strict in_array() check in \WP_Customize_Widgets::is_widget_rendered().

The rendered_widgets property is an associative array of 'widget-id' => true, so the previous loose check was actually also incorrect — it loosely compared the widget ID to true. Since the widget ID is the key, a ! empty() should cover it.

@afercia would you mind testing 50508.diff?

#3 in reply to: ↑ 2 @SergeyBiryukov
4 years ago

Replying to dlh:

would you mind testing 50508.diff?

Thanks for the patch! It appears to solve the immediate issue.

However, that still leaves an inconsistent structure of the rendered_sidebars and rendered_widgets properties:

rendered_sidebars:
array(5) {
  [0]=>
  string(9) "sidebar-1"
  [1]=>
  string(9) "sidebar-2"
  [2]=>
  string(9) "sidebar-1"
  [3]=>
  string(9) "sidebar-2"
  [4]=>
  string(9) "sidebar-1"
}
rendered_widgets:
array(7) {
  ["search-2"]=>
  bool(true)
  ["recent-posts-2"]=>
  bool(true)
  ["recent-comments-2"]=>
  bool(true)
  ["archives-2"]=>
  bool(true)
  ["categories-2"]=>
  bool(true)
  ["text-2"]=>
  bool(true)
  ["meta-2"]=>
  bool(true)
}

I think that can still lead to regressions like this in the future.

50508.2.diff attempts to bring some consistency by using the same structure for rendered_sidebars. As a positive side effect, this also removes duplicate values:

array(2) {
  ["sidebar-1"]=>
  bool(true)
  ["sidebar-2"]=>
  bool(true)
}

Since the class is final and these properties are protected, I think there should be no backward compatibility concerns in changing the structure. Could you double check?

Last edited 4 years ago by SergeyBiryukov (previous) (diff)

@dlh
4 years ago

#4 @dlh
4 years ago

Makes sense to me. The only thing I noticed was that the logic to export renderedSidebars and renderedWidgets assumes that every item in the respective property is set to true, which is currently accurate in practice, but isn't guaranteed. 50508.3.diff filters out falsey values just in case.

#5 @SergeyBiryukov
4 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 48299:

Customize: Correct the check for rendered widgets in WP_Customize_Widgets::is_widget_rendered().

Make the structure of ::$rendered_sidebars and ::$rendered_widgets properties consistent.

This resolves an issue with every widget being marked as inactive by default on the Widgets panel.

Props dlh, afercia, SergeyBiryukov.
Fixes #50508.

Note: See TracTickets for help on using tickets.