[wp-trac] [WordPress Trac] #42475: Customize: Autosaving message not sent to preview at first change

WordPress Trac noreply at wordpress.org
Wed Nov 8 20:23:12 UTC 2017


#42475: Customize: Autosaving message not sent to preview at first change
-------------------------------------+------------------
 Reporter:  westonruter              |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  4.9
Component:  Customize                |     Version:  4.9
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+------------------
Changes (by westonruter):

 * keywords:   => has-patch needs-testing


Old description:

> In `customize-controls.js` there is a `startAutosaving` function that
> gets called once a change is first made. It then in turn will start
> listening for changes to the `saved` state to then send an `autosaving`
> message to the preview when it goes dirty. However, the `saved` state
> also gets set to `false` (dirty) when a `change` event happens. This
> means that the `saved` state change handler is not getting fired with the
> first change.
>
> Easy way to see this behavior is to install the customizer-dev-tools
> plugin and run this from the console:
>
> {{{
> CustomizerDevTools.startLogging(/autosaving|saved|change/)
> }}}
>
> You'll see the `autosaving` message is not sent to the preview after the
> first change, but it will be sent after saving a draft and making a
> second change.
>
> Likewise, you can see the problem illustrated by hovering over links in
> the preview after the first change and see they lack the
> `customize_autosaved=on` parameter. However, after saving a draft and
> making a second change, then you'll see the param appear.

New description:

 In `customize-controls.js` there is a `startAutosaving` function that gets
 called once a change is first made. It then in turn will start listening
 for changes to the `saved` state to then send an `autosaving` message to
 the preview when it goes dirty. However, the `saved` state also gets set
 to `false` (dirty) when a `change` event happens. So there is somewhat of
 a race condition. This means that the `saved` state change handler is not
 getting fired with the first change.

 Easy way to see this behavior is to install the customizer-dev-tools
 plugin and run this from the console:

 {{{
 CustomizerDevTools.startLogging(/autosaving|saved|change/)
 }}}

 You'll see the `autosaving` message is not sent to the preview after the
 first change, but it will be sent after saving a draft and making a second
 change.

 Likewise, you can see the problem illustrated by hovering over links in
 the preview after the first change and see they lack the
 `customize_autosaved=on` parameter. However, after saving a draft and
 making a second change, then you'll see the param appear.

--

Comment:

 The solution is simply to call handler for `saved` state change when
 `startAutosaving` is being called. See [attachment:42475.diff].

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42475#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list