-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blocks: Preserves source of unrecognized blocks inside of Code Editor #39523
Conversation
Size Change: +7 B (0%) Total Size: 1.21 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me, can we add a quick test for this?
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. |
Either unit or e2e work here. unit can just be a simple serialization call but I guess e2e test would have better coverage. |
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
as you asked, so delivered! (thanks @youknowriad for the nudge) |
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
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 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
serializeBlock
function 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
serialize
and 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
trunk
so start in this branch, save the content, and then loadtrunk
to 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:
group
togrourp
.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.
onBlur
the Code Editor would wipe out content it couldn't recognize, making it impossible through the editor to setup a broken post to work with.