Repository navigation
Classic block: Optional chain on possibly null editor - #25163
Merged
Merged
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
|
sirreal
commented
Sep 9, 2020
ntsekouras
reviewed
Sep 9, 2020
ntsekouras
left a comment
Contributor
There was a problem hiding this comment.
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 <ntsekouras@outlook.com>
sirreal
marked this pull request as ready for review
September 9, 2020 12:00
Member
Author
|
Thanks for the review, @ntsekouras. I've reverted the second optional chain, this should be ready. |
2 of 6 tasks
This was referenced Mar 18, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
We've observed errors where
getContentis invoked onnullon 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: