Customizer: widget-synced triggers twice

I just noticed that widget-synced is triggered twice when you’re trying to edit a widget, click on a text field, write something, triggers widget-synced once and after that, if you click anywhere else it triggers a second time.

enter image description here

Is this default behavior and can it be prevented in a custom widget?


Pinging @WestonRuter

Solutions Collecting From Web of "Customizer: widget-synced triggers twice"

The reason for this is that the widget will run its update logic on keydown and also on change for a given input element. See

There are some tradeoffs made when widgets were added to the customizer to bring these PHP-driven interfaces into a JS-driven context. It wasn’t perfect and so this is part of the reason behind the JS Widgets feature plugin, to modernize how custom widgets are implemented in the customizer.

If you want to really just listen for when a widget actually changes its state, you can listen for the control’s underlying setting change instead. The setting will only be updated once after a given keydown and subsequent change event.

I kinda managed to fix it, don’t know if it’s the proper way, this is in case of sortable fields, using the stop event and checking if the “Apply” button is inside the widget: