1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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.
This commit is contained in:
Nick O'Leary 2019-03-15 18:50:58 +00:00
parent bdf68311b4
commit afe89c3621
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -28,15 +28,26 @@ var RED = (function() {
var hasDeferred = false; var hasDeferred = false;
var nodeConfigEls = $("<div>"+nodeConfig+"</div>"); var nodeConfigEls = $("<div>"+nodeConfig+"</div>");
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'); var srcUrl = $(el).attr('src');
if (srcUrl && !/^\s*(https?:|\/|\.)/.test(srcUrl)) { if (srcUrl && !/^\s*(https?:|\/|\.)/.test(srcUrl)) {
$(el).remove(); $(el).remove();
console.log("Appending script for",moduleId)
var newScript = document.createElement("script"); 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); $('body').append(newScript);
newScript.src = RED.settings.apiRootUrl+srcUrl; newScript.src = RED.settings.apiRootUrl+srcUrl;
hasDeferred = true; hasDeferred = true;
} else {
scriptCount--;
} }
}) })
if (!hasDeferred) { if (!hasDeferred) {