From 0d73b031c8fbe55eaef2e320894a3029d7d11e4d Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Fri, 17 Feb 2017 21:59:37 +0000 Subject: [PATCH] JavaScript: when starting Backbone history, stop if previously started. Prevent a potential error condition if Backbone history is started by a plugin or theme before core tries to start it. Props tfrommen. Fixes #39612. git-svn-id: https://develop.svn.wordpress.org/trunk@40076 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/revisions.js | 3 +++ src/wp-admin/js/theme.js | 6 ++++++ src/wp-includes/js/media-grid.js | 3 +++ src/wp-includes/js/media/views/frame/manage.js | 3 +++ 4 files changed, 15 insertions(+) diff --git a/src/wp-admin/js/revisions.js b/src/wp-admin/js/revisions.js index 5d3fe906b1..2949c49b6d 100644 --- a/src/wp-admin/js/revisions.js +++ b/src/wp-admin/js/revisions.js @@ -411,6 +411,9 @@ window.wp = window.wp || {}; // Start the router if browser supports History API if ( window.history && window.history.pushState ) { this.router = new revisions.Router({ model: this }); + if ( Backbone.History.started ) { + Backbone.history.stop(); + } Backbone.history.start({ pushState: true }); } }, diff --git a/src/wp-admin/js/theme.js b/src/wp-admin/js/theme.js index 159c6778d1..f919067329 100644 --- a/src/wp-admin/js/theme.js +++ b/src/wp-admin/js/theme.js @@ -1431,6 +1431,9 @@ themes.Run = { this.view.render(); this.routes(); + if ( Backbone.History.started ) { + Backbone.history.stop(); + } Backbone.history.start({ root: themes.data.settings.adminUrl, pushState: true, @@ -1884,6 +1887,9 @@ themes.RunInstaller = { this.view.render(); this.routes(); + if ( Backbone.History.started ) { + Backbone.history.stop(); + } Backbone.history.start({ root: themes.data.settings.adminUrl, pushState: true, diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index 5d0faa25f4..f0831fb3bb 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -844,6 +844,9 @@ Manage = MediaFrame.extend({ startHistory: function() { // Verify pushState support and activate if ( window.history && window.history.pushState ) { + if ( Backbone.History.started ) { + Backbone.history.stop(); + } Backbone.history.start( { root: window._wpMediaGridSettings.adminUrl, pushState: true diff --git a/src/wp-includes/js/media/views/frame/manage.js b/src/wp-includes/js/media/views/frame/manage.js index 5dd09a9b79..2b634331f3 100644 --- a/src/wp-includes/js/media/views/frame/manage.js +++ b/src/wp-includes/js/media/views/frame/manage.js @@ -259,6 +259,9 @@ Manage = MediaFrame.extend({ startHistory: function() { // Verify pushState support and activate if ( window.history && window.history.pushState ) { + if ( Backbone.History.started ) { + Backbone.history.stop(); + } Backbone.history.start( { root: window._wpMediaGridSettings.adminUrl, pushState: true