-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix broken editor when passing attributes as undefined or null and add warning for block authors #73149
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
Fix broken editor when passing attributes as undefined or null and add warning for block authors #73149
Changes from 5 commits
82e6464
43a1493
1c1fee6
e67d081
d7c5041
2a06573
99c3dbb
ac10381
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,19 @@ export const processBlockType = | |
| ), | ||
| }; | ||
|
|
||
| // Temporary fix to allow block authors time to fix blocks that register attributes as null or undefined. | ||
| if ( | ||
| ! blockType.attributes || | ||
| typeof blockType.attributes !== 'object' | ||
| ) { | ||
| warning( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also include a test for this? |
||
| 'The block "' + | ||
| name + | ||
| '" must not register attributes as `null` or `undefined`. Use an empty object (`attributes: {}`) or exclude the `attributes` key. In the next Gutenberg release, passing `null` or `undefined` for `attributes` will cause the block editor to crash.' | ||
|
||
| ); | ||
| blockType.attributes = {}; | ||
| } | ||
|
|
||
| const settings = applyFilters( | ||
| 'blocks.registerBlockType', | ||
| blockType, | ||
|
|
||
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.
Doesn't have to be temporary. Folks might encounter this in the future, too.
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'm fine with it not being temporary if others agree. I'd defer to folks with more expertise in block registration first.