-
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
DimensionsPanel: Fix site editor error on Columns block level screen #51252
DimensionsPanel: Fix site editor error on Columns block level screen #51252
Conversation
… therefore not null
Size Change: +2 B (0%) Total Size: 1.4 MB
ℹ️ View Unchanged
|
Flaky tests detected in b0ad156. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5184031998
|
@@ -208,7 +208,7 @@ export default function DimensionsPanel( { | |||
includeLayoutControls = false, | |||
} ) { | |||
const decodeValue = ( rawValue ) => { | |||
if ( typeof rawValue === 'object' ) { | |||
if ( rawValue && typeof rawValue === 'object' ) { |
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.
if ( rawValue && typeof rawValue === 'object' ) { | |
if ( rawValue !== null && typeof rawValue === 'object' ) { |
While the problem can be fixed as is, I think it is more rigorous to explicitly check for null
or not. This implementation is similar to the isObject() function.
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.
Thanks for the feedback! Usage isn't very consistent across Gutenberg, and I see a few other places where similar functions use a truthy check, e.g. in another isObject function and recent _.isEmpty
removals as in #51098 and #51096.
I have a slight preference for a truthy check over !== null
because, though it's less explicit, it seems to me a slightly more complete check and better matches to lodash's non-strict == null
check in isEmpty.
Let me know if you think we're missing anything by not including the strict check, and we can always open up a follow-up, though!
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.
Thanks for spotting the mistake, @andrewserong 🙏I will not be able to test this PR until tomorrow, but I will leave a comment.
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.
Thanks for the reviews! I've left the truthy check in as-is for now, but we can always look into a follow-up if there's any further feedback on it in terms of code style. I'll merge this in now so that the bug is fixed in |
… therefore not null (WordPress#51252)
What?
Related to: #50956
Fixes a site editor error when accessing the Columns block level screen, by ensuring that
rawValue
is truthy before attempting to access its keys.Why?
Sometimes values can be
null
and unfortunatelytypeof null
in JavaScript equalsobject
, so anull
value indecodeValues
can be passed toObject.keys()
which throws an error.I believe the value that was null in this case is
blockGap
. Further down in the function it looks likesetGapValues
will set gap values tonull
.How?
rawValue
before passing toObject.keys
Testing Instructions
Screenshots or screencast
Before this PR: