#36389 closed defect (bug) (fixed)
Selective refresh for widgets gets lost once `refresh` is used
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | Customize | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
I added add_theme_support( 'customize-selective-refresh-widgets' );
. When editing a text widget all works as expected. However, once a setting is changed that uses refresh
transport, the text widget then uses refresh
as well.
Attachments (6)
Change History (39)
#2
@
9 years ago
- Resolution set to invalid
- Status changed from new to closed
Sorry to waste your time @westonruter. In an attempt to track down the issue I have seen problems in other areas of the osfware I am working with. It does not look to be a CORE issue but likely something else. Should I be able to reproduce I will open a ticket. Thanks!
Nathan
#3
@
9 years ago
I wanted to add a note of my findings in case this behavior is seen by others. I placed the following code in a mu-plugins
plugin:
<?php add_action( 'after_setup_theme', function(){ add_theme_support( 'customize-selective-refresh-widgets' ); } );
This worked fine on the initial load in the Customizer, but then once the preview was fully refreshed it would not.
The solution was simply to add a slightly later priority to the action like this:
<?php add_action( 'after_setup_theme', function(){ add_theme_support( 'customize-selective-refresh-widgets' ); }, 11 );
#4
@
9 years ago
@scamartist26 that's strange. I don't see how a later priority would make a difference.
#5
@
9 years ago
I think it has something to do with sidebar registration. I am not sure, but I recreated the behavior with the Twenty Sixteen theme and no active plugins like this:
- Comment out line 123 from
functions.php
in Twenty Sixteen - Create
mu-plugins
directory with a{plugin}.php
file - Add this to file:
<?php add_action( 'after_setup_theme', function() { add_theme_support( 'customize-selective-refresh-widgets' ); });
- Go to Customizer/Widgets/Sidebar and add a text widget with some text. ( Note it refreshes partial )
- Next go to Customizer/Site Identity and change "Display Site Title and Tagline" to make preview refresh
- At this point, anything that would do a Partial refresh is lost.
- If you add the 11 priority to the
after_theme_setup
action, refresh the Customizer and run the test again you will see it now behaves correctly.
#6
@
9 years ago
- Keywords reporter-feedback removed
- Resolution invalid deleted
- Status changed from closed to reopened
I can reproduce this issue now.
#7
@
9 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 4.5
- Owner set to westonruter
- Status changed from reopened to accepted
#8
@
9 years ago
OK, I think the issue is this: when you edit a widget, it will be included among the customized
state and will be seen when accessing WP_Customize_Manager::unsanitized_post_values()
. The WP_Customize_Widgets::register_settings()
method is called at after_setup_theme
and it ensures that any widgets in the customized
state are registered up front. The WP_Customize_Widgets::get_selective_refreshable_widgets()
method is getting called before the widgets_init
is triggered, and because of this none of the widgets have been registered and so an empty array gets cached.
#9
@
9 years ago
- Keywords has-patch added; needs-patch removed
Ultimately it looks like the issue is that the widget settings are being registered too early, and that they need to be deferred until widgets_init
. @scamartist26 please test 36389.0.diff
#10
@
9 years ago
Seeing a problem with the patch. If the preview is refreshed after a new widget is added, it will not be included among the activeControls and so it will then appear to fade out even though the widget appears in the preview.
#11
@
9 years ago
There, 36389.1.diff fixes the issue by ensuring the preview filter for sidebars_widgets
gets added before the sidebars are iterated for adding the controls.
#12
@
9 years ago
Used the steps from comment:5 to reproduce the issue, 36389.1.diff fixes it for me.
#13
@
9 years ago
- Keywords has-unit-tests added
I've added unit tests for this issue in 36389.2.diff. Adding unit tests also necessitated introducing a static WP_Customize_Setting::reset_aggregated_multidimensionals()
to reset the protected static $aggregated_multidimensionals
variable after each test. (In hindsight, it may have been better to store the $aggregated_multidimensionals
as a non-static variable on WP_Customize_Manager
so that it would be cleaned up automatically after the manager is destructed.)
Unit tests are running on a PR: https://github.com/xwp/wordpress-develop/pull/149
+1 for commit for RC2?
This ticket was mentioned in Slack in #core by mike. View the logs.
9 years ago
#16
@
9 years ago
@DrewAPicture If we want to cause the reset_aggregated_multidimensionals method to not be parsed into to the devhub docs?
If the goal of the function is to only be used by unit tests, I think it makes sense to not expose it in our documentation.
This ticket was mentioned in Slack in #core by mike. View the logs.
9 years ago
#18
follow-up:
↓ 20
@
9 years ago
@jorbin: If we're going to add an @ignore
to the DocBlock, the docs should be complete and explicit about what it's supposed to be used for and why it exists. Docs are just as important internally as externally :-)
Side note: I recognize why we need it in core, but it definitely feels a little weird adding a method specifically for testing purposes. Like maybe the underlying code isn't flexible enough in its implementation to be easily testable in the first place. I register my hesitation to make this a habit.
#20
in reply to:
↑ 18
;
follow-up:
↓ 21
@
9 years ago
Replying to DrewAPicture:
Side note: I recognize why we need it in core, but it definitely feels a little weird adding a method specifically for testing purposes. Like maybe the underlying code isn't flexible enough in its implementation to be easily testable in the first place. I register my hesitation to make this a habit.
You're absolutely right. See my comment above:
Adding unit tests also necessitated introducing a static
WP_Customize_Setting::reset_aggregated_multidimensionals()
to reset the protected static$aggregated_multidimensionals
variable after each test. (In hindsight, it may have been better to store the$aggregated_multidimensionals
as a non-static variable onWP_Customize_Manager
so that it would be cleaned up automatically after the manager is destructed.)
So, what should be done specifically to prevent this method from being included in docs? Let it be like it is right now, but include @ignore
?
#21
in reply to:
↑ 20
@
9 years ago
Replying to westonruter:
Replying to DrewAPicture:
Side note: I recognize why we need it in core, but it definitely feels a little weird adding a method specifically for testing purposes. Like maybe the underlying code isn't flexible enough in its implementation to be easily testable in the first place. I register my hesitation to make this a habit.
You're absolutely right. See my comment above:
Adding unit tests also necessitated introducing a static
WP_Customize_Setting::reset_aggregated_multidimensionals()
to reset the protected static$aggregated_multidimensionals
variable after each test. (In hindsight, it may have been better to store the$aggregated_multidimensionals
as a non-static variable onWP_Customize_Manager
so that it would be cleaned up automatically after the manager is destructed.)
So, what should be done specifically to prevent this method from being included in docs? Let it be like it is right now, but include
@ignore
?
Yep, just add an @ignore
tag in there. And I'd change the description from "This is used by unit tests. It should not be used generally." to the more explicit "This is intended only for use by unit tests."
This ticket was mentioned in Slack in #core by mike. View the logs.
9 years ago
#24
@
9 years ago
@westonruter Why are you adding a trac-36389
group to the tests? @ticket 36389
seems to be sufficient.
I'm a bit worried about moving the filter/priorities around late in the cycle, but I couldn't break it while testing it with random themes/plugins and widgets. Otherwise 36389.3.diff looks good to me.
@
9 years ago
Removed extraneous unit test groups: https://github.com/xwp/wordpress-develop/pull/149/commits/31965b0163f269f022e2637dce0958c3da060afa
#25
@
9 years ago
I've also ensured that the changes here do not break the functionality and unit tests for the Customize Widgets Plus's Widget Posts module, which is does quite a bit of low-level integrations. The unit tests for the plugin pass, along with the Core unit tests with the plugin active.
This ticket was mentioned in Slack in #core by mike. View the logs.
9 years ago
@
9 years ago
Minimizing patch to address symptom, with underlying cause (previous patches) to be part of 4.6-early
#27
@
9 years ago
- Keywords has-unit-tests removed
I've opened #36431 to apply the full fix for the underlying problem in 4.6.
In the mean time, the fix for the symptom is 36389.minimized.0.diff.
This ticket was mentioned in Slack in #core-customize by mike. View the logs.
9 years ago
#29
@
9 years ago
After discussing in Slack( see the above link) I am +1 on commit to https://core.trac.wordpress.org/attachment/ticket/36389/36389.4.diff
@scamartist26 I cannot reproduce the issue. Here are the steps that I took:
First I did:
refresh
transport.Then to test:
refresh
transport, and note the entire preview refresh as expected.As I understand the issue in your ticket description, step 3 in my test should have instead caused a full refresh instead of a selective refresh. I cannot reproduce this, however.
Please elaborate.