chore(compass-crud): Do not recreate HadronDocument instances in render #3073
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.
Max spotted an issue where editing a stage would collapse expanded elements in the documents in all the previous ones which highlighted an issue that is partially responsible for the editing performance degradation that we currently see in Compass. Creating
HadronDocument
instances right in the render method combined with the fact that all the state inside the plugin is propagated down from the plugin root to the components through props lead to constant recreation of all the Documents in all the stages on every single change in the doc and this caused complete remounting of all components inside the Document component because Document and its children uuid was constantly changing.This patch fixes the issue by handling "raw" objects passed to the component a bit better: we check whether passed component is a HadronDocument type and only create an instance if it's not and if the underlying object changed.
There is still a somewhat noticeable lag when we actually fetch the documents and have to re-create these HadronDocument instances and update the views, but the massive slowdown that was happening on every change seems to be gone now.