From 6e09f902512dbbd61515604ed28df2c7c26a3cfd Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 5 Oct 2014 16:30:26 +0200 Subject: [PATCH] Fixed top navigation loading glitch A race condition occurred - router could execute promise.abortAll() even when top navigation didn't fully load. This caused top navigation presenter to throw "broken promise" error, which is reserved for promises made after core modules have been loaded. --- public_html/js/Bootstrap.js | 6 +++--- public_html/js/PresenterManager.js | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/public_html/js/Bootstrap.js b/public_html/js/Bootstrap.js index 3b9c39d7..ca32f8ab 100644 --- a/public_html/js/Bootstrap.js +++ b/public_html/js/Bootstrap.js @@ -2,9 +2,9 @@ var App = App || {}; App.Bootstrap = function(auth, router, util, promise, presenterManager) { - presenterManager.init(); - - promise.wait(auth.tryLoginFromCookie()) + promise.wait( + auth.tryLoginFromCookie(), + presenterManager.init()) .then(startRouting) .fail(function(error) { promise.wait(auth.loginAnonymous()) diff --git a/public_html/js/PresenterManager.js b/public_html/js/PresenterManager.js index 5cbb887b..7132f483 100644 --- a/public_html/js/PresenterManager.js +++ b/public_html/js/PresenterManager.js @@ -1,14 +1,16 @@ var App = App || {}; -App.PresenterManager = function(jQuery, topNavigationPresenter, keyboard) { +App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboard) { var lastContentPresenter = null; var $spinner; var spinnerTimeout; function init() { - initPresenter(topNavigationPresenter, [], function() {}); $spinner = jQuery('body').find('#wait'); + return promise.make(function(resolve, reject) { + initPresenter(topNavigationPresenter, [], resolve); + }); } function initPresenter(presenter, args, loaded) { @@ -72,4 +74,4 @@ App.PresenterManager = function(jQuery, topNavigationPresenter, keyboard) { }; -App.DI.registerSingleton('presenterManager', ['jQuery', 'topNavigationPresenter', 'keyboard'], App.PresenterManager); +App.DI.registerSingleton('presenterManager', ['jQuery', 'promise', 'topNavigationPresenter', 'keyboard'], App.PresenterManager);