fix(editor): Fix memory leak in Node Detail View by correctly unsubscribing from event buses (#6021)

This commit is contained in:
OlegIvaniv
2023-04-20 12:26:14 +02:00
committed by GitHub
parent 41660d9e28
commit 0970ec066d
13 changed files with 98 additions and 97 deletions

View File

@@ -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);