Fix dropped statuses when resolving missing types

pull/5314/head
GogoVega 2025-10-16 22:38:32 +02:00
parent b939305070
commit 6a88702152
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B
3 changed files with 16 additions and 1 deletions

View File

@ -529,7 +529,8 @@ var RED = (function() {
RED.comms.subscribe("status/#",function(topic,msg) {
var parts = topic.split("/");
var node = RED.nodes.node(parts[1]);
if (node) {
// Nodes of type unknown do not have i18n
if (node && typeof node._ === "function") {
if (msg.hasOwnProperty("text") && msg.text !== null && /^[@a-zA-Z]/.test(msg.text)) {
msg.text = node._(msg.text.toString(),{defaultValue:msg.text.toString()});
}

View File

@ -87,6 +87,15 @@ function publish(topic, data, retain, session, excludeSession) {
})
}
function republishStatus() {
for (const topic in retained) {
if (/^status(\/.*)?$/.test(topic)) {
connections.forEach((connection) => {
connection.send(topic, retained[topic]);
});
}
}
}
var api = module.exports = {
init: function(_runtime) {
@ -101,6 +110,8 @@ var api = module.exports = {
events.on("comms",handleCommsEvent);
events.removeListener("event-log",handleEventLog);
events.on("event-log",handleEventLog);
events.removeListener("comms:republish-status", republishStatus);
events.on("comms:republish-status", republishStatus);
},
/**

View File

@ -177,6 +177,9 @@ function installModule(module,version,url) {
}
if (info.nodes.length) {
events.emit("runtime-event",{id:"node/added",retain:false,payload:info.nodes});
// If the installed module resolves missing types, nodes will be started before the editor
// is notified of added types. Therefore, statuses published before the type resolution will be lost.
events.emit("comms:republish-status");
}
}
return info;