-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
On Block Invalidation and Transformations #11440
Comments
The invalidation process is a real problem for some block/theme developers who keep updating their blocks over time; either for fixing issues or adding new features. We have to create lots of entry inside the deprecated array in this case. Please provide a skipValidation setting option for blocks so the HTML code will generate completely based on the attribute values. There's a discussion around this issue on #10444 . |
From today's Slack thread, I think there are a few specific tasks that would help move this issue forward:
|
Comments/requests from an end user -
Another issue is the fate of the . I know they're often misused, but on our website we use them a lot, almost always for one of the following two reasons:
|
Valid html tags should not be stripped when converting from Classic to Blocks. Specifically for the image block: title and data-pin-description. Stripping those 2 tags means WordPress is deleting content. Valuable, valid content. People and businesses have spent lots of time, effort, and resources to have those tags in their images. |
I consider that the current block invalidation does not work with any type of block besides the extremely basic, and completely static blocks that ship with Core, as outlined in #12708 (comment). Imagine a client comes to you “Hey I want to present our services on our website, you know just a title and an image”. Two weeks later Another two weeks later Yet another two weeks later In addition I doubt the usefulness of the current validation during development, see #10444. |
Closing as a duplicate of #7604 |
One of the goals of Gutenberg was to drastically reduce the cases where users would inadvertently end up with the infamous HTML soup — nested
spans
anddivs
with inline styles that could break the layouts or reduce a website's usability — regardless of how the user introduces content (pasting from external sources, writing, creating blocks, installing blocks, etc). This has also been a goal for WordPress since the time it introduced the first WYSIWYG editor: to ensure semantic and clean markup. Balancing this aim while also empowering users to express themselves freely is one of the fundamental challenges of the WordPress publishing platform.A good example might the case of including a cite attribution in a Quote block. With Gutenberg, the resulting markup is semantic and the block is also easy to use. There's no need to understand the underlying HTML yet it is semantically enforced without manual requirements.
One principle that emerges is that blocks are generally opinionated about the markup produced, discarding or invalidating a block if something doesn't fit its requirements.
This is the context from which to look at the levers and tools in place for handling conflicts or block conversion issues.
Invalidation
Is the process with which a block source is compared with its output before the user interacts with a block. When this fails, for whatever reason, the block is considered invalid. This has been an extremely useful mechanism during the development process, highlighting issues with blocks, plugin compatibilities, and so on.
It's important to clarify that this is not a case of whether the markup is "valid" in terms of being HTML spec-compliant but about how the editor knows to create such markup and that its inability to create an identical result can be a strong indicator of potential data loss (the invalidation is then a protective measure).
It goes without saying that the general expectation for the user experience is that invalidation doesn't happen, and when it does, that it minimizes the amount of user intervention needed. However, considering an invalidation does occur, there are a few cases that need to be separated:
classes
orids
or evendata-attributes
). Even if they were to be discarded after a save cycle.figure
andimg
tags within an Image block) given the potential for losing content.The invalidation process can also be deconstructed in phases:
These are stacked in a way that favors performance and optimizes for the majority of cases. That is to say, the evaluation logic can become more sophisticated the further down it goes in the process. The first few checks have to be extremely efficient since they will be run for all valid blocks. However, once a block is detected as invalid — failing the three first steps — it is alright to spend more time determining validity before falling back to the user's decision.
Validate significance of differences
This is the area that could use improvements going forwards. Most of the currently reported issues come from differences that should not be significant yet produce an invalidation. There are generally two ways to approach this:
Related issues:
There are also intricacies that surface once blocks are extended.
Transformations
Another case of data transformation is present in the mechanism for switching a block to another block type. Transforming a block into another block can be destructive, depending on the heuristics established by the two blocks, the source and the destination. Block transformations also come in two shapes:
The first case knows about the block's attributes and is the one used in the main block transformation menu. It allows the most knowledge-transfer in the mapping of attributes. Issues in this conversion should be assigned to the individual blocks responsible for it (example, mapping a quote's cite to a plain paragraph).
The second case is used for extracting blocks out of a Classic block, or converting an HTML block into validated core blocks.
This process is grounded on the same handlers for pasting, which is why in general it removes elements as part of its cleanup process — #6102 —. The intention behind pasting is to clean-up the source without losing meaningful information. However, it could be assumed that given an existing chunk of Classic content the editor could be more lenient in the conversion. One way of handling this is separating both operations, pasting and raw conversion: #6878. Another possibility is to alert the user when something is removed.
Related issues:
Potential Tasks
The aim of this issue is to provide enough context for all these related problems so that any improvements can be discussed holistically. Some examples:
The text was updated successfully, but these errors were encountered: