Blocks: Preserves source of unrecognized blocks inside of Code Editor#39523
Merged
Blocks: Preserves source of unrecognized blocks inside of Code Editor#39523
Conversation
|
Size Change: +7 B (0%) Total Size: 1.21 MB
ℹ️ View Unchanged
|
youknowriad
approved these changes
Mar 24, 2022
Contributor
youknowriad
left a comment
There was a problem hiding this comment.
This makes sense to me, can we add a quick test for this?
Member
Author
|
I'll try @youknowriad but I guess it will have to be an end-to-end test yeah? I'll take a look and see if I can find some examples. |
Contributor
|
Either unit or e2e work here. unit can just be a simple serialization call but I guess e2e test would have better coverage. |
Member
Author
thanks for clarifying. I think I misread what you were after at first; should be easy to get this in a test in |
95d72c7 to
5c6a40f
Compare
Member
Author
|
as you asked, so delivered! (thanks @youknowriad for the nudge) |
Contributor
|
Thank you ❤️ |
Following the work of #38923 where we started preserving the source content for blocks that the editor fails to recognize, this patch uses that information in the Code Editor to ensure that we don't accidentally corrupt or lose content when making edits there. Previously the `serializeBlock` function, which generates the HTML for the Code Editor, would try to re-generated the saved content for blocks that we know are invalid. Because we know the input is invalid we can guarantee that the output will have even more problems. Now that `serializeBlock` function is aware of the source content for a block, and if the block is marked invalid _and_ that source exists it will pass that along to the output and skip the processing and re-generation of the saved content. This ensures that errors don't cascade and that unrelated edits to other blocks from the Code Editor won't destroy content in the marked-invalid blocks.
6848dcd to
4a77541
Compare
37 tasks
6 tasks
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.
Following the work of #38923 where we started preserving the source
content for blocks that the editor fails to recognize, this patch
uses that information in the Code Editor to ensure that we don't
accidentally corrupt or lose content when making edits there.
Previously the
serializeBlockfunction, which generates the HTMLfor the Code Editor, would try to re-generated the saved content
for blocks that we know are invalid. Because we know the input is
invalid we can guarantee that the output will have even more problems.
Now that
serializeBlockfunction is aware of the source content fora block, and if the block is marked invalid and that source exists
it will pass that along to the output and skip the processing and
re-generation of the saved content. This ensures that errors don't
cascade and that unrelated edits to other blocks from the Code Editor
won't destroy content in the marked-invalid blocks.
Testing Instructions
As we can see in the small diff, the serialize function only changes when a block is marked invalid and an original source is available. Because of this we should be able to assert by inspection that this patch is safe; it only comes into play when things are already broken.
Still, please consider the uses of
serializeand whether there could be situations in which preserving the source markup could trigger unexpected consequences.To test you only need to load the branch and create some invalid block content in a post. It may be difficult to do this from
trunkso start in this branch, save the content, and then loadtrunkto confirm the different behaviors.Not every invalid or unrecognized block will lead to data loss or corruption. Explore different kinds of block invalidations and see which ones are impacted by this change:
grouptogrourp.Screenshots or screencast
Behavior in
trunk- when opening the Code Editor we can see that unrecognized content can be immediately erased or corrupted.preserve-in-code-editor--trunk.mov
Behavior in this branch - we can see that not only is the source of unrecognized blocks preserved but additionally we can make edits to it without requiring that the editor can understand those edits.
preserve-in-code-editor--branch.mov
Note that until now it was not always possible to resolve issues with invalid blocks manually from the Code Editor. For some kinds of errors the editor would not load the appropriate markup that one would need in order to fix the block.
Conversely, until now it's been difficult to force blocks into an invalid state because of the same issue.
onBlurthe Code Editor would wipe out content it couldn't recognize, making it impossible through the editor to setup a broken post to work with.