Repository navigation
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 6 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. | ||
|
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. Doesn't have to be temporary. Folks might encounter this in the future, too.
Contributor
Author
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. I'm fine with it not being temporary if others agree. I'd defer to folks with more expertise in block registration first. |
||
| 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.' | ||
|
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. Also, this "in the next release it will crash", isn't accurate, is it? I think we can omit that whole sentence.
Contributor
Author
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. I wasn't sure. I figured having it be the most aggressive and then relaxing it would be better than starting with a longer timeline.
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. But it's technically not true, is it? I'd just remove it and keep the warning forever.
Contributor
Author
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.
I was planning to open a PR that removes it, set a reminder and then get it approved/merged when the time came :)
That's fine. I'll just remove it. |
||
| ); | ||
| blockType.attributes = {}; | ||
| } | ||
|
|
||
| const settings = applyFilters( | ||
| 'blocks.registerBlockType', | ||
| blockType, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.