WordPress.org

Make WordPress Core

#27657 closed defect (bug) (fixed)

Clicking 'Publish' before autosave fires does not publish a post

Reported by: jeremyfelt Owned by: azaozz
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.9
Component: Autosave Keywords: has-patch
Focuses: javascript Cc:

Description

As of [26995] via #25272, if you enter a title and then immediately click 'Publish', the post autosaves as a draft rather than publishing. A second click on 'Publish' is successful.

If you enter a title and click anywhere outside of the field before clicking on 'Publish', the action is successful.

Attachments (4)

27657.patch (469 bytes) - added by davidmarichal 17 months ago.
27657.diff (557 bytes) - added by Nessworthy 17 months ago.
Adds small timeout to #title blur's autosave. Address #27657
27657.2.patch (545 bytes) - added by davidmarichal 17 months ago.
27657.3.patch (864 bytes) - added by azaozz 17 months ago.

Download all attachments as: .zip

Change History (13)

@davidmarichal17 months ago

comment:1 @adamsilverstein17 months ago

  • Keywords needs-patch added

@davidmarichal thanks for your contribution!

testing your patch I am still able to reproduce the bug @jeremyfelt reported :(

It doesn't always happen - to reproduce, I'm typing a bit and quickly clicking publish without clicking anywhere else on the page - here is a screencast showing the issue with the patch applied. Note that after clicking publish I only get a draft, the post is not published.

Can you explain your thinking with the approach of unbinding the title blur handler?

Last edited 17 months ago by adamsilverstein (previous) (diff)

@Nessworthy17 months ago

Adds small timeout to #title blur's autosave. Address #27657

comment:2 @Nessworthy17 months ago

Added a small patch to hopefully fix this.

So, the blur event from wp-admin\js\post.js triggers an autosave when the #title input field is blurred. For some reason, if this autosave is triggered, submitting / publishing the post will not be triggered. Instead, the save trigger just seems to get ignored.

Adding a small timeout of 100ms to the blur event seems to have fixed the issue on minor testing, but I'm not 100% on what the impact of adding a timeout may be.

Testing the event by adding a title then causing the #title input field to lose focus still triggers an intended autosave, just 100ms later.

I presume @davidmarichal's attempt to remove the blur event for #title was to prevent the autosave from occurring, but the blur event will typically be triggered before the publish button is clicked (jsFiddle).

comment:3 @nacin17 months ago

  • Owner set to azaozz
  • Status changed from new to assigned

@davidmarichal17 months ago

comment:4 follow-up: @davidmarichal17 months ago

  • Keywords needs-patch removed

The blur event has the property relatedTarget.

The publish button is set as the relatedTarget if clicked. So then on blur, I check if the relatedTarget is equal to any of the submit buttons and return false. (jsFiddle)

Hope this fixes the issue.

comment:5 @azaozz17 months ago

Was testing something similar to 27657.2.patch. That should do it. It is the right approach and seems jQuery normalizes relatedTarget.

comment:6 in reply to: ↑ 4 @adamsilverstein17 months ago

  • Keywords has-patch added

Replying to davidmarichal:

The blur event has the property relatedTarget.

The publish button is set as the relatedTarget if clicked. So then on blur, I check if the relatedTarget is equal to any of the submit buttons and return false. (jsFiddle)

Hope this fixes the issue.

Excellent, tried the fiddle and the approach makes sense. Could maybe use more testing in trunk, seems good though - thanks!

comment:7 @azaozz17 months ago

...seems jQuery normalizes relatedTarget

Scratch that. On further testing relatedTarget is not set in IE. Can keep the same approach but needs more code :)

@azaozz17 months ago

comment:8 @azaozz17 months ago

27657.3.patch is a combination of 27657.diff and 27657.2.patch. Seems best would be to explicitly cancel the autosave when the form is being submitted.

comment:9 @azaozz17 months ago

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

In 27951:

When autosaving a new post for the first time after a title was typed, cancel the autosave if the user is submitting the form. (Includes a precommit fix for customize-controls.css.) Props Nessworthy, davidmarichal, fixes #27657

Note: See TracTickets for help on using tickets.