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
|
| } ) { | ||
| const decodeValue = ( rawValue ) => { | ||
| if ( typeof rawValue === 'object' ) { | ||
| if ( rawValue && typeof rawValue === 'object' ) { |
There was a problem hiding this comment.
| 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.
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!
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for spotting the mistake, @andrewserong 🙏I will not be able to test this PR until tomorrow, but I will leave a comment.
|
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
rawValueis truthy before attempting to access its keys.Why?
Sometimes values can be
nulland unfortunatelytypeof nullin JavaScript equalsobject, so anullvalue indecodeValuescan 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 likesetGapValueswill set gap values tonull.How?
rawValuebefore passing toObject.keysTesting Instructions
Screenshots or screencast
Before this PR: