diff --git a/packages/frontend/editor-ui/src/constants.ts b/packages/frontend/editor-ui/src/constants.ts index 6a512970a1..350410f71e 100644 --- a/packages/frontend/editor-ui/src/constants.ts +++ b/packages/frontend/editor-ui/src/constants.ts @@ -516,6 +516,7 @@ export const LOCAL_STORAGE_NDV_PANEL_WIDTH = 'N8N_NDV_PANEL_WIDTH'; export const LOCAL_STORAGE_FOCUS_PANEL = 'N8N_FOCUS_PANEL'; export const LOCAL_STORAGE_EXPERIMENTAL_DISMISSED_SUGGESTED_WORKFLOWS = 'N8N_EXPERIMENTAL_DISMISSED_SUGGESTED_WORKFLOWS'; +export const LOCAL_STORAGE_RUN_DATA_WORKER = 'N8N_RUN_DATA_WORKER'; export const BASE_NODE_SURVEY_URL = 'https://n8n-community.typeform.com/to/BvmzxqYv#nodename='; export const COMMUNITY_PLUS_DOCS_URL = diff --git a/packages/frontend/editor-ui/src/stores/pushConnection.store.ts b/packages/frontend/editor-ui/src/stores/pushConnection.store.ts index ba261e53f5..2969e4a1f9 100644 --- a/packages/frontend/editor-ui/src/stores/pushConnection.store.ts +++ b/packages/frontend/editor-ui/src/stores/pushConnection.store.ts @@ -7,6 +7,9 @@ import { useSettingsStore } from './settings.store'; import { useRootStore } from '@n8n/stores/useRootStore'; import { useWebSocketClient } from '@/push-connection/useWebSocketClient'; import { useEventSourceClient } from '@/push-connection/useEventSourceClient'; +import { useLocalStorage } from '@vueuse/core'; +import { LOCAL_STORAGE_RUN_DATA_WORKER } from '@/constants'; +import { runDataWorker } from '@/workers/run-data/instance'; export type OnPushMessageHandler = (event: PushMessage) => void; @@ -17,6 +20,8 @@ export const usePushConnectionStore = defineStore(STORES.PUSH, () => { const rootStore = useRootStore(); const settingsStore = useSettingsStore(); + const isRunDataWorkerEnabled = useLocalStorage(LOCAL_STORAGE_RUN_DATA_WORKER, false); + /** * Queue of messages to be sent to the server. Messages are queued if * the connection is down. @@ -63,7 +68,12 @@ export const usePushConnectionStore = defineStore(STORES.PUSH, () => { // The `nodeExecuteAfterData` message is sent as binary data // to be handled by a web worker in the future. if (data instanceof ArrayBuffer) { - data = new TextDecoder('utf-8').decode(new Uint8Array(data)); + if (isRunDataWorkerEnabled.value) { + await runDataWorker.onNodeExecuteAfterData(data); + return; + } else { + data = new TextDecoder('utf-8').decode(new Uint8Array(data)); + } } let parsedData: PushMessage; diff --git a/packages/frontend/editor-ui/src/workers/run-data/worker.ts b/packages/frontend/editor-ui/src/workers/run-data/worker.ts index 5dab723e41..087b95c882 100644 --- a/packages/frontend/editor-ui/src/workers/run-data/worker.ts +++ b/packages/frontend/editor-ui/src/workers/run-data/worker.ts @@ -2,6 +2,7 @@ import * as Comlink from 'comlink'; import { databaseConfig } from '@/workers/run-data/db'; import { initializeDatabase } from '@/workers/database'; import type { Promiser, DbId } from '@sqlite.org/sqlite-wasm'; +import type { NodeExecuteAfterData } from '@n8n/api-types/push/execution'; const state: { initialized: boolean; @@ -23,6 +24,18 @@ export const actions = { state.dbId = dbId; state.initialized = true; }, + onNodeExecuteAfterData(buffer: ArrayBuffer) { + const data = new TextDecoder('utf-8').decode(new Uint8Array(buffer)); + + let parsedData: NodeExecuteAfterData; + try { + parsedData = JSON.parse(data); + } catch (error) { + return; + } + + console.log('nodeExecuteAfterData in worker', parsedData); + }, }; export type RunDataWorker = typeof actions;