[wp-trac] [WordPress Trac] #39612: (Resolve) Error due to Backbone.History being started again

WordPress Trac noreply at wordpress.org
Tue Jan 17 08:21:17 UTC 2017


#39612: (Resolve) Error due to Backbone.History being started again
----------------------------+-----------------------------
 Reporter:  tfrommen        |      Owner:
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:
 Severity:  normal          |   Keywords:
  Focuses:  javascript      |
----------------------------+-----------------------------
 When using Backbone, an error is thrown if you (try to) start the history
 multiple times. For regular browsers, this means that JavaScript is
 effectively not working at all.

 In WordPress core, the history is just started without further ado. And
 this leads to problems when you have a plugin (or a theme, for that
 matter) that uses Backbone itself (and that maybe even checks for an
 already started history). Depending on the dependencies of individual
 JavaScript files, the plugin JS might be included earlier than the core
 JS. The plugin checks for a running history, doesn't find one, starts one,
 ... and then core comes along and implicitly triggers an error.

 This could be resolved by checking the history status before starting it,
 and then maybe either don't do anything at all, or stop (and then restart)
 the history.
 In my opinion, core is ''allowed'' to configure Backbone as needed, so
 stopping an already started history and then (re)starting it like core
 wants it to be is totally fine in my opinion.

 So, why isn't there a check right now?
 Does anyone see any problem when integrating such checks?

 Any third-party JS code is, of course, required to configure the root of
 the Backbone history just like core does - otherwise everything will break
 anyway.
 And if some plugin author decides to ignore this (or maybe just doesn't
 know this!), this would lead in either the core JS or the plugin JS not
 working properly (routing wouldn't happen as expected). But it does
 '''not''' result in '''no JavaScript at all''' being functional, which is
 a big plus in my opinion. :)

 So, once again, instead of doing this:

 {{{
 Backbone.history.start({ /* options */ });
 }}}

 we could '''either''' do this:

 {{{
 if ( ! Backbone.History.started ) {
     Backbone.history.start({ /* options */ });
 }
 }}}

 '''or''' that:

 {{{
 if ( Backbone.History.started ) {
     Backbone.history.stop();
 }
 Backbone.history.start({ /* options */ });
 }}}

 Any opinions?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39612>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list