-
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
Classic block: Optional chain on possibly null editor #25163
Conversation
We've observed errors where `getContent` is invoked on `null` on this line. Use optional chaining to prevent this error from happening.
Size Change: +53 B (0%) Total Size: 1.2 MB
ℹ️ View Unchanged
|
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.
This can still happen if you load and you click really fast the Classic block toolbar, before the init happens. So it can be an extra safeguard and handles the above case. Remove the second change and let's merge this! 💯
Co-authored-by: Nik Tsekouras <[email protected]>
Thanks for the review, @ntsekouras. I've reverted the second optional chain, this should be ready. |
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 👍 Thanks!
Description
We've observed errors where
getContent
is invoked onnull
on thisline. Use optional chaining to prevent this error from happening.
gutenberg/packages/block-library/src/classic/edit.js
Line 73 in 55edb95
I don't know how to reproduce this consistently, but I have observed the error regularly on a site of mine and this change fixes the error.
On my site, the error is triggered by adding a Classic block with some content, saving the post, reloading the post in the editor then selecting the Classic block:
Introduced in #23408.
How has this been tested?
Rebuilding the plugin zip with this change and uploading it to my site.
Screenshots
Types of changes
Bug fix: Fix an issue where the Classic block may throw an error when loaded in a post.
Checklist: