From afe89c36215775a319d2a09e38f64546ba35b27d Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 15 Mar 2019 18:50:58 +0000 Subject: [PATCH] Handle node configs with multiple external scripts properly If the config had multiple scripts, we were calling the done callback once for each script. This in turn led to duplicate flows being loaded. --- .../@node-red/editor-client/src/js/red.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/red.js b/packages/node_modules/@node-red/editor-client/src/js/red.js index 4d02a189a..ea9c0fd73 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/red.js +++ b/packages/node_modules/@node-red/editor-client/src/js/red.js @@ -28,15 +28,26 @@ var RED = (function() { var hasDeferred = false; var nodeConfigEls = $("
"+nodeConfig+"
"); - nodeConfigEls.find("script").each(function(i,el) { + var scripts = nodeConfigEls.find("script"); + var scriptCount = scripts.length; + scripts.each(function(i,el) { var srcUrl = $(el).attr('src'); if (srcUrl && !/^\s*(https?:|\/|\.)/.test(srcUrl)) { $(el).remove(); + console.log("Appending script for",moduleId) var newScript = document.createElement("script"); - newScript.onload = function() { $("body").append(nodeConfigEls); done() } + newScript.onload = function() { + scriptCount--; + if (scriptCount === 0) { + $("body").append(nodeConfigEls); + done() + } + } $('body').append(newScript); newScript.src = RED.settings.apiRootUrl+srcUrl; hasDeferred = true; + } else { + scriptCount--; } }) if (!hasDeferred) {