Altinn / app-frontend-react

Altinn application React frontend
BSD 3-Clause "New" or "Revised" License
18 stars 31 forks source link

Faster save processing, reworking `useNodeValidation()` #2724

Closed olemartinorg closed 2 days ago

olemartinorg commented 3 days ago

Description

When form data is saved, we get new validations from the backend (when the app has implemented backend validation, at least). Previously, we saved the last processed validations pretty much everywhere (luckily only as a reference) so that we could make sure all StoreValidationsInNodeWorker components had done their job and stored new validations if needed. This caused lots of state updates on all nodes for every save operation, and worsened performance.

Now, the useNodeValidation() hook will instead subscribe to the validation store and will only re-run validation when that changes. It will then save which backend validations have been processed into the Registry, so that we can useWaitForNodesToValidate() to wait until they have processed their validations (or, at least, useNodeValidation() has run to completion).

This also means that NodesContext no longer has to store the latest validations, and also means that it can now only be 'ready' or 'not ready' (no longer 'processing the last save'). The node generator will now only become 'not ready' after a save if new components are introduced (typically if a row has been added).

In addition to this, a few minor changes. Either because they were tiny, or stuff I had to do because tests failed:

Related Issue(s)

Verification/QA

sonarcloud[bot] commented 3 days ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
88.7% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud