-
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
Block API: Fix the block 'edit' property validation #57193
Conversation
Size Change: +260 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
@@ -168,7 +168,7 @@ describe( 'blocks', () => { | |||
it( 'should reject blocks with an invalid edit function', () => { | |||
const blockType = { | |||
save: noop, | |||
edit: 'not-a-function', |
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.
We can explicitly disallow strings, which is a valid element type for React. WDYT?
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.
WFM
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.
Yes, looks good and tree-shaking ensures that only the used utils is bundled.
Let's make sure we don't pin the version of the dependency in the blocks package.
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.
Nice find 👍
Nice, all goo to land it 🚀 |
077fd13
to
a8b5bf5
Compare
What?
PR fixes the block's
edit
property validation when bootstrapping the block types, failing for memoized components.Why?
The main requirement for the
edit
property is to be a valid React component for the block editor to render, which usually means having the type of afunction
, but can be a specialobject
when wrapped in React APIs.I noticed this while working on #57173. The HoCs like
withSelect
will returnpure
or memoized components.How?
Use the
isValidElementType
from the officialreact-is
library to check theedit
property's validity correctly.P.S. If this check is too extensive, we can create our custom utility using primitives provided by the library.
Testing Instructions
The "edit" property must be a valid function.
error on the trunk.Patch
Testing Instructions for Keyboard
Same