-
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: Deprecate isValidBlockContent
#38794
Conversation
Size Change: +98 B (0%) Total Size: 1.16 MB
ℹ️ View Unchanged
|
2787918
to
a51947f
Compare
a51947f
to
36336cf
Compare
Potentially this is a conflict with #38794 and once `isValidBlockContent` is gone we might be able to remove this change.
36336cf
to
d4998ae
Compare
Potentially this is a conflict with #38794 and once `isValidBlockContent` is gone we might be able to remove this change.
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.
LGTM. You might want to wait for a review from someone who is more familiar with the code.
Potentially this is a conflict with #38794 and once `isValidBlockContent` is gone we might be able to remove this change.
I didn't find much on sourcegraph: There were a few matches on the wpdirectory.net, though: Most of them seems like a bundled version of Gutenberg, but I didn't dive super deep into every single one. Overall, it seems like it isn't a wildly popular function.
👍
It is part of the public API so I'd rather not remove it, even if there aren't many publicly facing results. The way I saw deprecations work in Gutenberg was marking the function as deprecated, which you already did, and then wait at least two Gutenberg versions or longer if needed. A sensible way to proceed here would be to merge this PR, make the change visible on slack, and then create an issue to remove the function later on. Even if it ends up being removed after WP 6.0 is released to give the plugin authors time to adjust, that sounds fine. |
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.
Looks good! Please also add a corresponding changelog entry.
also cc @ellatrix @mcsf @noisysocks |
d4998ae
to
e990701
Compare
Thanks for looking that up @adamziel! that's a great idea I hadn't considered. looks good then. I didn't suspect we'd find much; still could be some uses out there but I bet the risk is low here. I added CHANGELOG entries but I don't know what I'm doing, so I added them under |
Potentially this is a conflict with #38794 and once `isValidBlockContent` is gone we might be able to remove this change.
Potentially this is a conflict with #38794 and once `isValidBlockContent` is gone we might be able to remove this change.
Potentially this is a conflict with #38794 and once `isValidBlockContent` is gone we might be able to remove this change.
The `isValidBlockContent` function attempts to validate a block by re-generating its output but does so by ignoring any `innerBlocks` that might exist. Since blocks can change their output based on the presence or content of its inner blocks this will lead to incorrect results from the validator. `validateBlock` also makes this mistake however it is fixable since it requires passing in the block itself (fixable in another patch once there are no longer two interfaces for what appears to be the same purpose). `isValidBlockContent` doesn't pass in the block and so is fundamentally limited in being able to validate properly. This limitation also means that we can't rely on `isValidBlockContent` once we start threading source information into blocks; that is, as we improve our ability to catch and fix or preserve issues with the block markup, this function provides no way forward to incorporate those updates. After scouring through the commit logs I was unable to find a clear purpose for this second validation method and in Core it only seems to be used as a convenience function for tests. We're deprecating it in this patch because it's an exposed public interface and it's not clear if anyone relies on it.
2b7bb5b
to
7b13d9e
Compare
Description
The
isValidBlockContent
function attempts to validate a block byre-generating its output but does so by ignoring any
innerBlocks
that might exist. Since blocks can change their output based on the
presence or content of its inner blocks this will lead to incorrect
results from the validator.
validateBlock
also makes this mistake however it is fixable sinceit requires passing in the block itself (fixable in another patch
once there are no longer two interfaces for what appears to be the
same purpose).
isValidBlockContent
doesn't pass in the block andso is fundamentally limited in being able to validate properly.
This limitation also means that we can't rely on
isValidBlockContent
once we start threading source information into blocks; that is, as
we improve our ability to catch and fix or preserve issues with the
block markup, this function provides no way forward to incorporate
those updates.
After scouring through the commit logs I was unable to find a clear
purpose for this second validation method and in Core it only seems
to be used as a convenience function for tests. We're deprecating it
in this patch because it's an exposed public interface and it's not
clear if anyone relies on it.
Testing Instructions
There are two testable changes in this PR:
isValidBlockContent
?What do we think about the deprecation? Should we schedule removal?
Should we outright remove it instead?
validateBlock
we haveremoved the tests and constraints on
isValidBlockContent
. We couldpreserve them but I want to avoid as much confusion as possible and
suggest people only use
validateBlock
.The only affected code in Core should be the tests, so if they pass
then there's nothing more to test.
Types of changes
As part of ongoing work to preserve existing unrecognized content (via invalid or missing blocks) this patch is deprecating an interface for block validation that overlooks inner blocks and parse failures. Because of this and because of the broader issue the editor has a tendency to corrupt or lose content on save, even for unrelated changes.
This change works to make it easier to account for inner blocks on validation as well as better preservation of those unrecognized bits.
Checklist:
*.native.js
files for terms that need renaming or removal).