be a bit more dilligent about including visitedBusses

This commit is contained in:
Tamius Han 2026-01-14 22:38:08 +01:00
parent 8a4985e6a3
commit f25749470b

View File

@ -89,6 +89,7 @@ export default class EventBus {
}
send(command: string, commandData: any, context: EventBusContext = {}) {
context.visitedBusses = [...context.visitedBusses ?? [], this.uuid];
// execute commands we have subscriptions for
if (this.commands?.[command]) {
@ -111,13 +112,12 @@ export default class EventBus {
} catch (e) {
if (command !== 'reload-required') {
// We shouldn't let reload-required command to trigger new reload-required commands.
this.send('reload-required', {});
this.send('reload-required', {}, {visitedBusses: [this.uuid]});
}
}
};
// call forwarding functions if they exist
if (!context?.borderCrossings?.iframe) {
for (const forwarding of this.iframeForwardingList) {
forwarding.fn(
command,
@ -126,15 +126,12 @@ export default class EventBus {
...context,
borderCrossings: {
...context?.borderCrossings,
iframe: true
// iframe: true // we actually no longer check this prop, we should instead rely on visitedBusses
}
}
);
}
this.sendToTunnel(command, commandData, context);
} else {
console.warn('message was already sent to iframe, doing nothing ...')
}
if (context?.stopPropagation) {
return;
@ -148,6 +145,10 @@ export default class EventBus {
* @param config
*/
sendToTunnel(command: string, config: any, context: EventBusContext = {}) {
if (!context.visitedBusses) {
console.error('Visited busses is missing from contextn. This is illegal.');
return;
}
context.visitedBusses = [...context.visitedBusses ?? [], this.uuid];
if (!this.disableTunnel && typeof window !== 'undefined') {
@ -205,7 +206,7 @@ export default class EventBus {
const payload = event.data.payload as EventBusMessage;
console.info(this.name, 'received message from iframe. command:', payload);
if (!payload.context) {
if (!payload.context?.visitedBusses) {
console.warn('Received iframe message without context. Doing nothing in order to avoid infinite loop. Event:', event);
return;
}