feat(v2): warn public form filler when form has changed on server-side #3569
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.
Problem
As originally raised by @mantariksh in #3457 (comment), we should not refresh the public form when the server state has changed. This may cause users to lose their currently filled in form fields. Instead, we should display a warning that form state has changed and the submission may fail due to such changes.
This PR implements that warning and prevents server side form changes from refreshing the current loaded form.
This is done by storing the initially fetched form and never changing it, whilst displaying a toast if the newly fetched form does change.
Possible future enhancements
The current methodology does a deep comparison between the current "cached" form and the form retrieved from the server, which may be inefficient. I don't think it will negatively impact responsiveness though, since the effect will not cause any rerenders -- even if a toast is shown a rerender is not triggered.
In the future, we may consider returning the
_v
prop when we retrieve the public form, a prop MongoDB exposes that declares the current version of the form, and compare that against the "cached" version for a simpler check.Screenshots