Skip to content

Commit

Permalink
Saving: Avoid unsetting previewWindow on unload event
Browse files Browse the repository at this point in the history
Unload can be triggered in Firefox merely by the writing to the interstitial window. Only delete once a redirect has been evaluated (and not closed).
  • Loading branch information
aduth committed Jul 6, 2018
1 parent 103f37b commit ccd822a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions editor/components/post-preview-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export class PostPreviewButton extends Component {
*/
setPreviewWindowLink( url ) {
const { previewWindow } = this;
if ( previewWindow ) {

// Once popup redirect is evaluated, even if already closed, delete
// reference to avoid later assignment of location in a post update.
delete this.previewWindow;

if ( previewWindow && ! previewWindow.closed ) {
previewWindow.location = url;
}
}
Expand Down Expand Up @@ -75,12 +80,6 @@ export class PostPreviewButton extends Component {
this.getWindowTarget()
);

// When popup is closed or redirected by setPreviewWindowLink, delete
// reference to avoid later assignment of location in a post update.
this.previewWindow.onbeforeunload = () => {
delete this.previewWindow;
};

if ( ! isAutosaveable ) {
return;
}
Expand Down

0 comments on commit ccd822a

Please sign in to comment.