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

Added a check for null as well #50461

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

Added a check for null as well #50461

wants to merge 2 commits into from

Conversation

CryZo
Copy link

@CryZo CryZo commented May 9, 2023

What?

This PR adds a null check to the use-setting component.

Why?

Because we had the case, that a combination of a faulty theme.json and ACF blocks crashed the Gutenberg editor on one of customers websites - on production! -.- Tn this case the components constructor got null instead of undefined or a valid component data model.

How?

I added a null check as well.

Testing Instructions

Unfortunately I have no clue how exactly we got there. However the more stable this code gets, the better - right?

Testing Instructions for Keyboard

n/a

@CryZo CryZo requested a review from ellatrix as a code owner May 9, 2023 08:13
@github-actions
Copy link

github-actions bot commented May 9, 2023

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @CryZo! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 9, 2023
Copy link
Contributor

@alexstine alexstine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of failing checks on this PR. One suggestion below. Please let me know if I can assist further.

@@ -132,7 +132,7 @@ export default function useSetting( path ) {
blockName
);

if ( undefined !== result ) {
if ( undefined !== result || null !== result ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do this instead?

Suggested change
if ( undefined !== result || null !== result ) {
if ( ! result ) {

This is one drawback to JavaScript.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :) I thought it had an purpose, that result was checked that explicit there. But I would suggest to solve it on both if statements like this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it in the other if statements as well. I hope it fits better now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

One more thing: I noticed, that the last commits on trunk failed. So my changes may be innocent.

@skorasaurus skorasaurus added the [Package] Components /packages/components label May 11, 2023
@mirka mirka added [Package] Block editor /packages/block-editor and removed [Package] Components /packages/components labels May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block editor /packages/block-editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants