Blocks: Move filter for registering block types before validation happens #5076
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.
Description
When reviewing #4777 I noticed that
registerSidebar
function reuses some logic fromregisterBlockType
. I also discovered that for both functions it is possible to use a filter which changes to the settings object after validation happened. See https://github.com/WordPress/gutenberg/pull/4777/files#r166887072. What it means in practice is that even if originally passed settings are valid, everyone can update them with corrupted data and it won't stop registration with the proper warning. This PR fixes it forregisterBlockType
method.I also added small refactoring which uses
jest-console
package to validateconsole.error
calls.How Has This Been Tested?
I added a new unit test to ensure that it works as expected.
Types of changes
Bug fix (non-breaking change which fixes an issue).
Checklist: