Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#34738 closed defect (bug) (fixed)

Customizer preview elements lose or misplace their preview data

Reported by: clorith's profile Clorith Owned by: westonruter's profile westonruter
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Customize Keywords: has-patch commit
Focuses: Cc:

Description

As first reported by @pagelab in https://wordpress.org/support/topic/inconsistent-behavior-of-javascript-clickchange-events-in-the-customizer

When making changes to widget settings in the customizer, they will forget (and "reset") the other changes made except the most recent one when generating the preview.

Reproducible with weird outcomes:
Add a Text widget
Write a title, preview updates with the title as expected
Write some content, preview updates with the content but removes the title.

You can also remove the title, but the preview keeps the title, and mix and match as you please it seems, some times it will include the data though (tested with twenty fifteen, no active widgets and the text widget from core)

Attachments (3)

34738.0.diff (16.0 KB) - added by westonruter 9 years ago.
https://github.com/xwp/wordpress-develop/pull/133
34738.1.diff (36.4 KB) - added by westonruter 9 years ago.
Additional changes: https://github.com/xwp/wordpress-develop/compare/3ee37d1...c2fabed
34738.2.diff (36.4 KB) - added by westonruter 9 years ago.
Do customize_post_value_set before customize_post_value_set_{setting_id}: https://github.com/xwp/wordpress-develop/commit/268a38778f0b925a5d34a86ac458029b12eff4fe

Download all attachments as: .zip

Change History (20)

#1 @westonruter
9 years ago

  • Keywords reporter-feedback added

@Clorith I'm not seeing this issue with the Text widget.

Here is what I see in 4.4 beta 4 at r35701: https://cloudup.com/cAz3UhFnOQa

#2 @westonruter
9 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to westonruter
  • Status changed from new to accepted
  • Version changed from trunk to 4.3

I am seeing the issue clearly with the toggles in the “Simple widget” as linked to from the support forum. With further testing, I'm able to reproduce the issue with Text widget as well. I'm trying to isolate where the regression is.

#3 @westonruter
9 years ago

  • Keywords reporter-feedback removed

#4 @westonruter
9 years ago

With git-bisect I was able to identify that the regression was introduced in r35007 (e158ff2) for #32103.

#5 @westonruter
9 years ago

  • Keywords has-patch needs-testing needs-unit-tests dev-feedback added

In 34738.0.diff:

  • Move $is_previewed from WP_Customize_Setting child classes to parent.
  • Introduce customize_post_value_set and customize_post_value_set_{$setting_id} actions. Use to defer calling WP_Customize_Setting::preview() until it has a value to set, and to clear out the previewed-applied flag for a multidimensional-aggregated value whenever its post value is updated.
  • Ensure that a multidimensional setting's post value is applied to preview if the setting is previewed.
  • Ensure that a widget instance's JS value is set as the post value.

Needs new unit tests to cover the new scenarios.

#6 @westonruter
9 years ago

@valendesigns Please review my PR as it is. I need to follow up with unit tests still.

This ticket was mentioned in Slack in #core by wonderboymusic. View the logs.


9 years ago

#8 @westonruter
9 years ago

  • Version changed from 4.3 to trunk

#9 @westonruter
9 years ago

@Clorith @pagelab Please test the patch.

#10 @Clorith
9 years ago

Seeing expected behavior when applying 34738.0.diff

Texts are going where they should, and I am not able to make it retain removed text inputs like before.

#11 @pagelab
9 years ago

Yes, I also confirm that is working as expected now with 34738.0.diff applied. Tested with the same "Simple Widget" plugin as before.

#12 @valendesigns
9 years ago

  • Keywords needs-testing removed

@westonruter the patch looks good, and is also working for me using the test widget.

@pagelab Your test widget has a couple errors I had to fix before I could use it since my environment is in debug mode. The most important being that you can't convert $instance to a string. So you're CSS id should be something like this $id = "{$this->id_base}-toggle-{$this->number}";. The other two are on line 58 & 149 $instance['title'] doesn't exist when you first create a widget so you need to do a ternary isset check like so $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; to avoid PHP warnings. At any rate, thank you for supplying something to test with.

#13 @pagelab
9 years ago

@valendesigns yes, that's correct. Thanks for pointing this out.

This ticket was mentioned in Slack in #core by wonderboymusic. View the logs.


9 years ago

#15 @westonruter
9 years ago

  • Keywords commit added; needs-unit-tests dev-feedback removed

In 34738.1.diff:

  • Add unit tests, including new assertions for WP_Customize_Setting::preview() for scalar, multidimensional, and custom types
  • Add unit tests for WP_Customize_Manager::set_post_value() and the related actions.
  • Add unit tests for WP_Customize_Widgets::call_widget_update().
  • Use customize_post_value_set_{setting_id} instead of general customize_post_value_set to clear_aggregated_multidimensional_preview_applied_flag.
  • Remove obsolete WP_Customize_Setting::value() call to apply_multidimensional_preview_value() call since now handled automatically via deferred-preview, and remove the new apply_multidimensional_preview_value() method since it is no longer needing to be called separately (due to deferred-preview being applied on customize_post_value_set action).

@westonruter
9 years ago

Do customize_post_value_set before customize_post_value_set_{setting_id}: https://github.com/xwp/wordpress-develop/commit/268a38778f0b925a5d34a86ac458029b12eff4fe

#16 @westonruter
9 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 35724:

Customize: Ensure that a setting (especially a multidimensional one) can still be previewed when the post value to preview is set after preview() is invoked.

  • Introduce customize_post_value_set_{$setting_id} and customize_post_value_set actions which are done when WP_Customize_Manager::set_post_value() is called.
  • Clear the preview_applied flag for aggregated multidimensional settings when a post value is set. This ensures the new value is used instead of a previously-cached previewed value.
  • Move $is_preview property from subclasses to WP_Customize_Setting parent class.
  • Deferred preview: Ensure that when preview() short-circuits due to not being applicable that it will be called again later when the post value is set.
  • Populate post value for updated-widget with the (unsanitized) JS-value in WP_Customize_Widgets::call_widget_update() so that value will be properly sanitized when accessed in WP_Customize_Manager::post_value().

Includes unit tests with assertions to check the reported issues and validate the fixes.

Fixes defect introduced in [35007].
See #32103.
Fixes #34738.

#17 @westonruter
9 years ago

In 36645:

Docs: Use markdown instead of HTML for code formatting.

Fixes phpdoc usage in [36622], [36608], [35724], [35307].

See #35898.
See #35869.
See #34738.
See #33552.

Note: See TracTickets for help on using tickets.