fix(slice-machine): reconcile state from filesystem when possible (#1100,DT-1705) #1187
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.
Context
See the Loom video below for a full walkthrough, should help understanding what's being made here.
Slice Machine UI has a "layered" kind of state for custom types and slices, from fresher and often-changing to more static and less-often-changing ones:
The issue this PR addresses is that while we prefer changes to be made on in the UI (updating state 1. first), sometimes changes have to happen on the filesystem (updating state 2.). This is often the case with richtext labels for example (#1100) because those cannot (yet) be configured through the UI.
When this happens this leads to some confusion in the UI because state 2. (filesystem) goes ahead of state 1. (browser). The UI having no mechanism to resolve that kind of conflicts it leads to a surprising UX for users, sometime having them lose part of their work.
This PR (partially) fixes: #1100, DT-1705
The Solution
This PR improves the experience of users encountering the above scenario by allowing the UI the reconcile states 1. and 2. when state 2. (filesystem) goes ahead of state 1. (browser) and state 1. (browser) was left untouched before state 2. (filesystem) went ahead when working on custom types and slices.
As stated by the above chart, this is not perfect as if both states were touched, state 1. (browser) will overwrite state 2. (filesystem). I don't think we want to develop a smart conflict resolution algorithm to improve that further, we'd rather want to invest more in the UI to make it more capable and reduce the need to update models from the file system.
I implemented the above in the
useServerState
hook which is the central point of the application where SWR is used and causing the initial issue (#1100). I'm not really sure there's a better workaround to update the Redux store properly here.Checklist before requesting a review
[OPT] Preview
https://www.loom.com/share/aa0371e2cb184660bf7cde958481fc10?sid=baa3677e-b0be-4d4f-9da5-ef47be462053