Skip to content
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 Editor: Update callers to handle when getBlockType returns undefined #34891

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

@amustaque97
Copy link
Contributor

@amustaque97 amustaque97 commented Sep 16, 2021

This commit has partial changes related to #34462. It is based on some manual testing.

Description

In most cases we either need to check if blockType is truthy before using it, or use optional chaining if it makes sense. eg const icon = blockType?.icon;

How has this been tested?

Testing Instruction can be found here #34346 (comment)

Screenshots

Screenshot 2021-09-17 02:48:48

Types of changes

Fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

cc @gwwar

…fined

This commit has partial changes. It is based on some manual testing.
@amustaque97 amustaque97 requested a review from ellatrix as a code owner Sep 16, 2021
Copy link
Contributor

@gwwar gwwar left a comment

Thanks for taking a look @amustaque97! I left a few notes since some of the usages have a few gotchas. Feel free to ask if anything I noted was unclear.

packages/block-editor/src/store/actions.js Outdated Show resolved Hide resolved
packages/blocks/src/store/selectors.js Outdated Show resolved Hide resolved
packages/blocks/src/api/factory.js Outdated Show resolved Hide resolved
packages/block-editor/src/components/block-title/index.js Outdated Show resolved Hide resolved
packages/blocks/src/api/factory.js Outdated Show resolved Hide resolved
packages/blocks/src/api/utils.js Outdated Show resolved Hide resolved
@@ -198,7 +198,7 @@ export function getSaveContent( blockTypeOrName, attributes, innerBlocks ) {
*/
export function getCommentAttributes( blockType, attributes ) {
return reduce(
blockType.attributes,
blockType?.attributes,
Copy link
Contributor

@gwwar gwwar Sep 16, 2021

To match the style of this package, if we're passing blockType as an argument from getBlockType( blockName ), let's update that instead of adding sanitization in this function.

Copy link
Contributor Author

@amustaque97 amustaque97 Sep 18, 2021

@gwwar can you explain this change? I'm not clear with your comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants