From 463d101f3592e6df4afd66c4d0fde0cb4aec34cc Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Tue, 5 Nov 2024 15:17:41 +0200 Subject: [PATCH] fix(editor): Fix emitting `n8nReady` notification via `postmessage` on new canvas (#11558) --- packages/editor-ui/src/views/NodeView.v2.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/editor-ui/src/views/NodeView.v2.vue b/packages/editor-ui/src/views/NodeView.v2.vue index 9cd22e3ea3..5d8905be82 100644 --- a/packages/editor-ui/src/views/NodeView.v2.vue +++ b/packages/editor-ui/src/views/NodeView.v2.vue @@ -1276,7 +1276,13 @@ function removeSourceControlEventBindings() { function addPostMessageEventBindings() { window.addEventListener('message', onPostMessageReceived); +} +function removePostMessageEventBindings() { + window.removeEventListener('message', onPostMessageReceived); +} + +function emitPostMessageReady() { if (window.parent) { window.parent.postMessage( JSON.stringify({ command: 'n8nReady', version: rootStore.versionCli }), @@ -1285,10 +1291,6 @@ function addPostMessageEventBindings() { } } -function removePostMessageEventBindings() { - window.removeEventListener('message', onPostMessageReceived); -} - async function onPostMessageReceived(messageEvent: MessageEvent) { if ( !messageEvent || @@ -1516,6 +1518,8 @@ onBeforeMount(() => { if (!isDemoRoute.value) { pushConnectionStore.pushConnect(); } + + addPostMessageEventBindings(); }); onMounted(() => { @@ -1536,6 +1540,8 @@ onMounted(() => { canvasStore.stopLoading(); void externalHooks.run('nodeView.mount').catch(() => {}); + + emitPostMessageReady(); }); void usersStore.showPersonalizationSurvey(); @@ -1544,7 +1550,6 @@ onMounted(() => { }); addSourceControlEventBindings(); - addPostMessageEventBindings(); addWorkflowSavedEventBindings(); addBeforeUnloadEventBindings(); addImportEventBindings();