Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The PDF subform test would sometimes fail when filling out the subform data. The problem was that the data element did not exist in the instance data, and so the data model could not be determined to be writable. Right before adding the new subform entry, the test would fill out two fields in the main form, and immediately click the add subform button. This causes a save to happen at the same time as we are adding a subform. When saving, we get updated instance data from the backend, and when adding a subform, we get the data element back which we manually append to our local instance state. In this case we can have a race condition where the backend does not have the new subform data element when processing the save, and so the updated instance data does not contain this. If that response is somehow processed after we add the new subform data element to our local instance state this would get overwritten by the new instance data from the save response. Then when entering the subform, we cannot find the data element.
The solution is to use
locking
in the same way we do for custom actions and file uploading. This causes us to wait for save before sending the request, and block new saves until we are finished.I also noticed that the loading state for custom buttons (which are used for exiting subform) was a bit insufficient. It only shows loading while a server action is pending, but just like navigation buttons, we can wait for saving / validation where we should also show a spinner. So I added the
useIsProcessing
hook to show a loading state while the entire button callback is running. To make this work properly, I removed thepromisify
wrappers around client actions, which would effectively create a new promise and resolve it after asetTimeout(..., 0)
, which undermines our ability to await these properly. I am not sure what the reason for this was in the first place as I cannot se any mention of it in the original PR.Related Issue(s)
Verification/QA
kind/*
label to this PR for proper release notes grouping