Make WordPress Core

Opened 10 years ago

Closed 9 years ago

#27657 closed defect (bug) (fixed)

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

Reported by: jeremyfelt's profile jeremyfelt Owned by: azaozz's profile 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 10 years ago.
27657.diff (557 bytes) - added by Nessworthy 9 years ago.
Adds small timeout to #title blur's autosave. Address #27657
27657.2.patch (545 bytes) - added by davidmarichal 9 years ago.
27657.3.patch (864 bytes) - added by azaozz 9 years ago.

Download all attachments as: .zip

Change History (13)

#1 @adamsilverstein
10 years 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 10 years ago by adamsilverstein (previous) (diff)

@Nessworthy
9 years ago

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

#2 @Nessworthy
9 years 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).

#3 @nacin
9 years ago

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

#4 follow-up: @davidmarichal
9 years 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.

#5 @azaozz
9 years ago

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

#6 in reply to: ↑ 4 @adamsilverstein
9 years 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!

#7 @azaozz
9 years 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 :)

@azaozz
9 years ago

#8 @azaozz
9 years 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.

#9 @azaozz
9 years 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.