From ada7b4a4e8c1eb85f79a6b959b1e9ab37528f5f5 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 22 May 2015 15:07:04 +1000 Subject: [PATCH] FIX: guard against concurrent loading of deferred assets --- .../javascripts/discourse/lib/load-script.js.es6 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/assets/javascripts/discourse/lib/load-script.js.es6 b/app/assets/javascripts/discourse/lib/load-script.js.es6 index 5b6c0e4eb..f0398cecd 100644 --- a/app/assets/javascripts/discourse/lib/load-script.js.es6 +++ b/app/assets/javascripts/discourse/lib/load-script.js.es6 @@ -1,6 +1,7 @@ /* global assetPath */ const _loaded = {}; +const _loading = {}; function loadWithTag(path, cb) { const head = document.getElementsByTagName('head')[0]; @@ -29,9 +30,20 @@ export default function loadScript(url, opts) { // If we already loaded this url if (_loaded[url]) { return resolve(); } + if (_loading[url]) { return _loading[url].then(resolve);} + + var done; + _loading[url] = new Ember.RSVP.Promise(function(_done){ + done = _done; + }); + + _loading[url].then(function(){ + delete _loading[url]; + }); const cb = function() { _loaded[url] = true; + done(); resolve(); };