Skip to content

Validation: Re-runs after every PATCH hammers slow noIncrementalUpdates-validation #4137

@olemartinorg

Description

@olemartinorg

Description of the bug

On the backend, we have a validation concept called noIncrementalUpdates, specifically made for cases where validation is slow (i.e. when it needs API lookups or complex checks). We want to reduce the calls to run these validations until we absolutely have to.

On the frontend, we now have a trigger that can cause this validation to run way too often:

// Since process/next returns non-incremental validations, we need to also check these to see when they are removed
const refetchInitialValidations = useRefetchInitialValidations(false);
useEffect(() => {
// No need to invalidate initial validations right away
if (isFirstRender.current) {
isFirstRender.current = false;
return;
}
// Adding or deleting an attachment can lead to changes in both the data model and an update
// in the attachments data elements, which can lead to two updates right after each other,
// so debouncing a little so that we don't call validate too much as it can be heavy.
const timer = setTimeout(() => refetchInitialValidations(), 1000);
return () => clearTimeout(timer);
}, [refetchInitialValidations, instanceDataChanges, lastSaved]);

This was introduced in #2462, which had fixes for some validation issues. We should look into finding a better fix for this, while trying our best to keep the user experience at the current level (or not that far below the one we have now). Fixing this is expected to cause slow-running validations to not update in the UI unless the user explicitly triggers re-validation (i .e. by trying to submit the form, or some other interaction). It might be wise to take a step back and look into introducing a button for letting the user re-validate in cases like this.

Steps To Reproduce

  1. Trigger the 'showAllErrors' validation mode
  2. Make changes to form data
  3. Observe a call to /validate happens after every PATCH

Additional Information

A somewhat long discussion about the topic:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/validationrelated to form validation rules/messageskind/bugSomething isn't workingorg/krtsquad/dataIssues that belongs to the named squad.

    Type

    No fields configured for Bug.

    Projects

    Status

    ⭐ Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions