Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(n8n Form Node): Form Trigger does not wait in multi-form mode #11404

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions packages/cli/src/webhooks/waiting-forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ export class WaitingForms extends WaitingWebhooks {
});
}

private async reloadForm(req: WaitingWebhookRequest, res: express.Response) {
try {
await sleep(1000);

const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
const page = await axios({ url });

if (page) {
res.send(`
<script>
setTimeout(function() {
window.location.reload();
}, 1);
</script>
`);
}
} catch (error) {}
}

async executeWebhook(
req: WaitingWebhookRequest,
res: express.Response,
Expand All @@ -56,30 +75,17 @@ export class WaitingForms extends WaitingWebhooks {
}

if (execution.data.resultData.error) {
throw new ConflictError(`The execution "${executionId}" has finished with error.`);
const message = `The execution "${executionId}" has finished with error.`;
this.logger.debug(message, { error: execution.data.resultData.error });
throw new ConflictError(message);
}

if (execution.status === 'running') {
if (this.includeForms && req.method === 'GET') {
await sleep(1000);

const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
const page = await axios({ url });

if (page) {
res.send(`
<script>
setTimeout(function() {
window.location.reload();
}, 1);
</script>
`);
}

return {
noWebhookResponse: true,
};
await this.reloadForm(req, res);
return { noWebhookResponse: true };
}

throw new ConflictError(`The execution "${executionId}" is running already.`);
}

Expand Down
16 changes: 10 additions & 6 deletions packages/cli/src/webhooks/waiting-webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export class WaitingWebhooks implements IWebhookManager {
}

if (execution.data?.resultData?.error) {
throw new ConflictError(`The execution "${executionId} has finished already.`);
const message = `The execution "${executionId}" has finished with error.`;
this.logger.debug(message, { error: execution.data.resultData.error });
throw new ConflictError(message);
}

if (execution.finished) {
Expand Down Expand Up @@ -182,23 +184,25 @@ export class WaitingWebhooks implements IWebhookManager {
if (this.isSendAndWaitRequest(workflow.nodes, suffix)) {
res.render('send-and-wait-no-action-required', { isTestWebhook: false });
return { noWebhookResponse: true };
} else if (!execution.data.resultData.error && execution.status === 'waiting') {
}

if (!execution.data.resultData.error && execution.status === 'waiting') {
const childNodes = workflow.getChildNodes(
execution.data.resultData.lastNodeExecuted as string,
);

const hasChildForms = childNodes.some(
(node) =>
workflow.nodes[node].type === FORM_NODE_TYPE ||
workflow.nodes[node].type === WAIT_NODE_TYPE,
);

if (hasChildForms) {
return { noWebhookResponse: true };
} else {
throw new NotFoundError(errorMessage);
}
} else {
throw new NotFoundError(errorMessage);
}

throw new NotFoundError(errorMessage);
}

const runExecutionData = execution.data;
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/templates/form-trigger.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,8 @@
console.error('Error:', error);
});

const isWaitingForm = window.location.href.includes('form-waiting');
if(isWaitingForm) {
const interval = setInterval(function() {
const isSubmited = document.querySelector('#submitted-form').style.display;
if(isSubmited === 'block') {
Expand All @@ -760,6 +762,7 @@
}
window.location.reload();
}, 2000);
}
}
});
</script>
Expand Down
Loading