mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 05:04:05 -08:00
fix(editor): Suppress dev server websocket messages in workflow view (#7808)
This commit is contained in:
parent
117962d473
commit
685ffd7413
|
@ -136,6 +136,7 @@ const onMouseLeave = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const receiveMessage = ({ data }: MessageEvent) => {
|
const receiveMessage = ({ data }: MessageEvent) => {
|
||||||
|
if (data?.includes('"command"')) {
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(data);
|
const json = JSON.parse(data);
|
||||||
if (json.command === 'n8nReady') {
|
if (json.command === 'n8nReady') {
|
||||||
|
@ -150,6 +151,7 @@ const receiveMessage = ({ data }: MessageEvent) => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const onDocumentScroll = () => {
|
const onDocumentScroll = () => {
|
||||||
if (insideIframe.value) {
|
if (insideIframe.value) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ const renderComponent = createComponentRenderer(WorkflowPreview);
|
||||||
let pinia: ReturnType<typeof createPinia>;
|
let pinia: ReturnType<typeof createPinia>;
|
||||||
let workflowsStore: ReturnType<typeof useWorkflowsStore>;
|
let workflowsStore: ReturnType<typeof useWorkflowsStore>;
|
||||||
let postMessageSpy: vi.SpyInstance;
|
let postMessageSpy: vi.SpyInstance;
|
||||||
|
let consoleErrorSpy: vi.SpyInstance;
|
||||||
|
|
||||||
const sendPostMessageCommand = (command: string) => {
|
const sendPostMessageCommand = (command: string) => {
|
||||||
window.postMessage(`{"command":"${command}"}`, '*');
|
window.postMessage(`{"command":"${command}"}`, '*');
|
||||||
|
@ -23,6 +24,7 @@ describe('WorkflowPreview', () => {
|
||||||
setActivePinia(pinia);
|
setActivePinia(pinia);
|
||||||
workflowsStore = useWorkflowsStore();
|
workflowsStore = useWorkflowsStore();
|
||||||
|
|
||||||
|
consoleErrorSpy = vi.spyOn(console, 'error');
|
||||||
postMessageSpy = vi.fn();
|
postMessageSpy = vi.fn();
|
||||||
Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
|
Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
|
||||||
writable: true,
|
writable: true,
|
||||||
|
@ -32,6 +34,10 @@ describe('WorkflowPreview', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
consoleErrorSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
it('should not call iframe postMessage when it is ready and no workflow or executionId props', async () => {
|
it('should not call iframe postMessage when it is ready and no workflow or executionId props', async () => {
|
||||||
renderComponent({
|
renderComponent({
|
||||||
pinia,
|
pinia,
|
||||||
|
@ -227,4 +233,18 @@ describe('WorkflowPreview', () => {
|
||||||
expect(emitted().close).toBeDefined();
|
expect(emitted().close).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not do anything if no "command" is sent in the message', async () => {
|
||||||
|
const { emitted } = renderComponent({
|
||||||
|
pinia,
|
||||||
|
props: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
window.postMessage('commando', '*');
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(console.error).not.toHaveBeenCalled();
|
||||||
|
expect(emitted()).toEqual({});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4260,6 +4260,7 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onPostMessageReceived(message: MessageEvent) {
|
async onPostMessageReceived(message: MessageEvent) {
|
||||||
|
if (message?.data?.includes('"command"')) {
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(message.data);
|
const json = JSON.parse(message.data);
|
||||||
if (json && json.command === 'openWorkflow') {
|
if (json && json.command === 'openWorkflow') {
|
||||||
|
@ -4310,6 +4311,7 @@ export default defineComponent({
|
||||||
this.workflowsStore.activeWorkflowExecution = json.execution;
|
this.workflowsStore.activeWorkflowExecution = json.execution;
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async onImportWorkflowDataEvent(data: IDataObject) {
|
async onImportWorkflowDataEvent(data: IDataObject) {
|
||||||
await this.importWorkflowData(data.data as IWorkflowDataUpdate, 'file');
|
await this.importWorkflowData(data.data as IWorkflowDataUpdate, 'file');
|
||||||
|
|
Loading…
Reference in a new issue