fix(editor): Fix memory leak in Node Detail View by correctly unsubscribing from event buses (#6021)
This commit is contained in:
@@ -2516,6 +2516,20 @@ export default mixins(
|
||||
}
|
||||
}
|
||||
},
|
||||
onBeforeUnload(e) {
|
||||
if (this.isDemo || window.preventNodeViewBeforeUnload) {
|
||||
return;
|
||||
} else if (this.uiStore.stateIsDirty) {
|
||||
const confirmationMessage = this.$locale.baseText(
|
||||
'nodeView.itLooksLikeYouHaveBeenEditingSomething',
|
||||
);
|
||||
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
|
||||
return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
|
||||
} else {
|
||||
this.startLoading(this.$locale.baseText('nodeView.redirecting'));
|
||||
return;
|
||||
}
|
||||
},
|
||||
async newWorkflow(): Promise<void> {
|
||||
this.startLoading();
|
||||
await this.resetWorkspace();
|
||||
@@ -2597,23 +2611,7 @@ export default mixins(
|
||||
document.addEventListener('keydown', this.keyDown);
|
||||
document.addEventListener('keyup', this.keyUp);
|
||||
|
||||
// allow to be overriden in e2e tests
|
||||
// @ts-ignore
|
||||
window.onBeforeUnloadNodeView = (e) => {
|
||||
if (this.isDemo) {
|
||||
return;
|
||||
} else if (this.uiStore.stateIsDirty) {
|
||||
const confirmationMessage = this.$locale.baseText(
|
||||
'nodeView.itLooksLikeYouHaveBeenEditingSomething',
|
||||
);
|
||||
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
|
||||
return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
|
||||
} else {
|
||||
this.startLoading(this.$locale.baseText('nodeView.redirecting'));
|
||||
return;
|
||||
}
|
||||
};
|
||||
window.addEventListener('beforeunload', window.onBeforeUnloadNodeView);
|
||||
window.addEventListener('beforeunload', this.onBeforeUnload);
|
||||
},
|
||||
getOutputEndpointUUID(nodeName: string, index: number): string | null {
|
||||
const node = this.workflowsStore.getNodeByName(nodeName);
|
||||
@@ -3972,6 +3970,7 @@ export default mixins(
|
||||
document.removeEventListener('keydown', this.keyDown);
|
||||
document.removeEventListener('keyup', this.keyUp);
|
||||
window.removeEventListener('message', this.onPostMessageReceived);
|
||||
window.removeEventListener('beforeunload', this.onBeforeUnload);
|
||||
|
||||
this.$root.$off('newWorkflow', this.newWorkflow);
|
||||
this.$root.$off('importWorkflowData', this.onImportWorkflowDataEvent);
|
||||
|
||||
@@ -135,18 +135,16 @@ export default mixins().extend({
|
||||
}
|
||||
});
|
||||
// refresh when a modal closes
|
||||
this.eventBus.on('destinationWasSaved', async () => {
|
||||
this.$forceUpdate();
|
||||
});
|
||||
this.eventBus.on('destinationWasSaved', this.onDestinationWasSaved);
|
||||
// listen to remove emission
|
||||
this.eventBus.on('remove', async (destinationId: string) => {
|
||||
await this.onRemove(destinationId);
|
||||
});
|
||||
this.eventBus.on('remove', this.onRemove);
|
||||
// listen to modal closing and remove nodes from store
|
||||
this.eventBus.on('closing', async (destinationId: string) => {
|
||||
this.workflowsStore.removeAllNodes({ setStateDirty: false, removePinData: true });
|
||||
this.uiStore.stateIsDirty = false;
|
||||
});
|
||||
this.eventBus.on('closing', this.onBusClosing);
|
||||
},
|
||||
destroyed() {
|
||||
this.eventBus.off('destinationWasSaved', this.onDestinationWasSaved);
|
||||
this.eventBus.off('remove', this.onRemove);
|
||||
this.eventBus.off('closing', this.onBusClosing);
|
||||
},
|
||||
computed: {
|
||||
...mapStores(
|
||||
@@ -173,6 +171,13 @@ export default mixins().extend({
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
onDestinationWasSaved() {
|
||||
this.$forceUpdate();
|
||||
},
|
||||
onBusClosing() {
|
||||
this.workflowsStore.removeAllNodes({ setStateDirty: false, removePinData: true });
|
||||
this.uiStore.stateIsDirty = false;
|
||||
},
|
||||
async getDestinationDataFromBackend(): Promise<void> {
|
||||
this.logStreamingStore.clearEventNames();
|
||||
this.logStreamingStore.clearDestinationItemTrees();
|
||||
|
||||
Reference in New Issue
Block a user