Handle multiple simultaneous block editor layouts#16184
Merged
Conversation
bergmania
approved these changes
Apr 30, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Prerequisites
Description
The original RFC for block editors states that a Block Editor should theoretically be able to store multiple simultaneous block layouts.
However, while removing the explicit JSON technology dependencies in the Block Editor implementation in favour of a strongly typed approach, we (yours truly) accidentally managed to enforce one type of block layout for all layouts in any given Block Editor. And that's obviously incorrect.
Unfortunately we cannot know about the concrete block layout implementations of other Block Editors when (de)serializing a concrete Block Editor instance. This means we can only (de)serialize layouts that belong to the concrete Block Editor instance in question.
To that end, this PR introduces a custom JSON converter - the
JsonBlockValueConverter. This converter explicitly handles the (de)serialization of the block layouts while farming off the rest of theBlockValue(de)serialization to the default JSON serializer.Potential data loss
The
JsonBlockValueConverterwill actively discard any "unknown" block layouts while (de)serializing a concrete Block Editor instance. This can very well result in data loss, i.e. if a subsequent save is performed on top of a serialized value.In effect, though, we have yet to actually see multiple simultaneous block layouts within a Block Editor instance. As a matter of fact, V13 will positively not work with multiple layouts within a Block Grid instance, and possibly it will also break for a Block List. So - in terms of potential data loss, we are likely in the clear here 😉
Testability
While working through various scenarios for this PR, I quickly realised that the RTE would not allow for unit/integration testing these things, because it relied on some obsolete constructors and subsequent static instance resolving. In other words - I had to fix that in this PR too, in order to test all these changes properly.
Testing this PR
It should be possible to edit Block Editors as per usual:
See also the added and updated unit/integration tests for interesting scenarios 😄