From 0f3462e3c963a433346fee044315d71a29fbc505 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Thu, 2 Nov 2023 12:57:35 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[open-formulieren/open-forms#357?= =?UTF-8?q?2]=20Fix=20potential=20race=20condition=20on=20WebKit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport-of: 585 --- src/components/FormStep/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/FormStep/index.js b/src/components/FormStep/index.js index 79967fe2b..e9d39d73a 100644 --- a/src/components/FormStep/index.js +++ b/src/components/FormStep/index.js @@ -406,7 +406,7 @@ const FormStep = ({ * * - `LOGIC_CHECK_INTERRUPTED` When there's no point/change in state to be expected by the logic * check - * - `BLOCK_SUBMISSION` When the the logic is checking and the form should be disabled for + * - `BLOCK_SUBMISSION` When the logic is checking and the form should be disabled for * submission. * - `LOGIC_CHECK_DONE` When the logic check is done and the form should be enabled for * submission. @@ -710,7 +710,7 @@ const FormStep = ({ * * During evaluation, the following actions are/may be dispatched: * - * - `BLOCK_SUBMISSION` When the the form midfier by a humer (`modifiedByHuman`) and the form + * - `BLOCK_SUBMISSION` When the form was modified by a human (`modifiedByHuman`) and the form * should be disabled for submission. * - `ERROR` When an error occurred while evaluating the form logic. * - `FORMIO_CHANGE_HANDLED` When the change is successfully handled . @@ -726,6 +726,12 @@ const FormStep = ({ const onFormIOChange = async (changed, flags, modifiedByHuman) => { // formio form not mounted -> nothing to do if (!formRef.current) return; + // Under some conditions and engines (e.g. WebKit), `onFormIOChange` can be triggered while + // logicChecking is currently running (that is the scheduled logic check with `setTimeout` is ongoing). + // While it is running, `canSubmit` is set to `false` because of the fired `BLOCK_SUBMISSION` action. + // We don't want to get in conflict with the current check if the change doesn't come from the user. + // See https://github.com/open-formulieren/open-forms/issues/3572 for an example. + if (!modifiedByHuman && logicChecking) return; // backend logic leads to changes in FormIO configuration, which triggers onFormIOInitialized. // This in turn triggers the onFormIOChange event because the submission data is set