-
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
Editor: Defer block validation until after source application #16569
Conversation
@@ -943,6 +959,10 @@ export function* resetEditorBlocks( blocks, options = {} ) { | |||
yield* resetLastBlockSourceDependencies( Array.from( updatedSources ) ); | |||
} | |||
|
|||
if ( options.validate ) { |
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.
I considered not making this an option and instead the default behavior. For standard editor usage, we always call resetEditorBlocks
with validate: true
. It only really makes sense as an option for usage where a third-party might dispatch this action with the result of a default wp.blocks.parse
function call, and thus the re-validation would be redundant (note: it would be redundant, but not otherwise harmful aside the performance overhead).
For standard editor usage, we always call
resetEditorBlocks
withvalidate: true
.
Edit: In reflection, this statement is totally wrong, and the reason it's set up the way it is is so that we can call resetEditorBlocks
without frequent validation, since we call it on e.g. every key press.
packages/blocks/src/api/parser.js
Outdated
/** | ||
* Options for parse. | ||
* | ||
* @property {Object<string,Function>} sources An object defining custom source |
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.
I don't think this JSDoc matches. Might be a copy/paste thing?
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.
I don't think this JSDoc matches. Might be a copy/paste thing?
Oof. Good call. Updated to something more reasonable in the rebased 272e660.
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.
👍
@@ -662,4 +662,48 @@ describe( 'validation', () => { | |||
expect( isValid ).toBe( true ); | |||
} ); | |||
} ); | |||
|
|||
describe( 'validate', () => { |
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.
Should we also test for validation failures?
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.
Should we also test for validation failures?
I don't think it's necessary. The purpose of these test cases is not to verify validation (which are a separate set of test cases), but to ensure the assignment of the validation result.
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.
Makes sense.
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, just a couple of comments on a JSDoc and the tests.
The E2E tests should also be fixed.
b16b364
to
44d7e5c
Compare
The unit tests should be fixed now in the rebased 272e660.
These are trickier, and appear to be a legitimate issue. I thought perhaps it might have just been an issue of the editor "readiness" being deferred, but some rough attempts at debugging (e.g. |
How should we proceed? Is it a symptom of an underlying issue or are the tests just not compatible? |
A new post would not have original content against which to compare.
I suspect this may be improved / resolved by dfa0d03. Previously, we'd have issue with block templates where it would try to run validation over the template blocks, but because there is no original content against which to compare for a new post, the validation would error. This never occurs in |
As of #17153, meta attribute values are no longer initialized into parsed blocks, which invalidates this approach. |
Fixes #4989
Related: #16402, #16316
This pull request seeks to opt out of validation for the initial blocks parse, instead awaiting the application of sourced attributes. This allows, for example, meta attribute values to be applied such that validation can occur with expected results (see #4989).
Testing Instructions:
Ensure unit tests pass:
Verify that updating a block with an attribute sourced by a meta attribute and persisted to the block's markup (via
save
) is valid after saving and reloading the editor content.Example plugin: https://gist.github.com/aduth/e44d104996277dd9d6b08edf403030c5